CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 17

Threaded View

  1. #1
    Join Date
    Apr 2002

    Question Popup menu on mousemove message


    I am trying to implement a popup menu that opens on a mousemove message rather than a right mouse click. When the cursor is in a particular region of the client window, the popup menu should be displayed. If the mouse moves to a different region, the original popup menu should 'disappear' and a modified menu should appear that is specific to that region.

    I am finding this quite difficult to get working - does anyone have any ideas for me? This has been my approach so far:

    In the OnMouseMove handler - I check the cursor coordinates and create/load the popup menu specific to the region. Because I am using TrackPopupMenu to display the popup menu, no other mouse move messages were getting through until I closed that menu or select an item from it.

    My attempt at a solution (after searching on CodeGuru) was to use a thread specific hook to catch the mousemove message - to do this I used:

    SetWindowsHookEx(WH_MOUSE, MouseHook, NULL,GetCurrentThreadId());
    The MouseHook function is declared as:

    LRESULT CALLBACK MouseHook(int nCode, WPARAM wParam,  LPARAM lParam)
    In this function I check if it is a mousemove message and then call the same code to check the region and create a new popup menu.

    My problem is that the popup menu will display the first time and then will remain on the screen until I close it or select an item from it .... if I step into the code, the MouseHook function is being called and sometimes fires the code to create a new menu, but it doesn't seem to work. I am not sure if my problem lies in how I am implementing the creation of the menu or how I am trying to create and use the windows hook.

    Sorry for the lengthy explanation, but can anyone shed some light on this problem? Or perhaps suggest a better way to achieve the same result??

    Last edited by Emster; April 14th, 2004 at 05:46 PM.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.