CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2001
    Posts
    9

    Intercepting menu mouseover / havefocus events

    Hi,

    I would like add some code to a VB6 project that changes the status bar message when the mouse is moved over a menu (or sub-menu) item.

    This is so that when the user moves the mouse over a menu item, a description of the function of the menu item can be displayed in the status bar.

    I have looked at API functions as a way of doing this but it seems as though there are no appropriate events defined within the VB development area that can be used. Has anyone got any idea how to do this??????

    Paul



  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Intercepting menu mouseover / havefocus events

    You will have to subclass the form,
    intercepting the WM_NCMOUSEMOVE event,
    and if it's wParam is HTMENU then get the x position and the y position thus:


    'snip from windowproc....
    '\\ Mouse move
    ElseIf wMsg = WM_NCMOUSEMOVE then
    If wParam = HTMENU then
    x = LoWord(lParam)
    y = HiWord(lParam)
    End If
    'snip

    '\\ --[LoWord]-----------------------------------------------------------------------------
    '\\ Returns the low word component of a long value
    '\\ Parameters:
    '\\ dw - The long of which we need the LoWord
    '\\
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function LoWord(dw as Long) as Integer
    If dw And &H8000& then
    LoWord = &H8000 Or (dw And &H7FFF&)
    else
    LoWord = dw And &HFFFF&
    End If
    End Function

    '\\ --[HiWord]-----------------------------------------------------------------------------
    '\\ Returns the high word component of a long value
    '\\ Parameters:
    '\\ dw - The long of which we need the HiWord
    '\\
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function HiWord(dw as Long) as Integer
    If dw And &H80000000 then
    HiWord = (dw \ 65535) - 1
    else
    HiWord = dw \ 65535
    End If
    End Function




    And use the MenuItemFromPoint API to decide which menu the mouse moved over.

    Hope this helps,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Mar 2001
    Posts
    9

    Re: Intercepting menu mouseover / havefocus events

    Thanks for posting that

    But the problem really is in which event do I place the code?? VB submenu items only have a click event associated with them and I want the code to fire when the mouse is moved over a submenu item for which there is no event.

    Do you see my problem??

    Paul


  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Intercepting menu mouseover / havefocus events

    I do indeed see the problem.

    When VB was designed, they chose a set of Events from the much larger set of Windows Messages available as strndard and wrote these up as Visual basic events.

    However, they left an awful lot of them out.

    Fortunately, after version 5 they gave us the wherewithall to overcome this limitation - which is something I am working on at the moment. My current project is to write an event handler to implement all these missing events - it should be ready for Beta by the middle of next month.

    If you want a head start, there are articles on Subclassing off my home site http://www.merrioncomputing.com and if you wish to drop me an email from there I will send you the source as it stands. (I am reluctant to put my email address on this site as it may get picked up by a spammer).

    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured