April 14th, 2004, 03:38 AM
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:
The MouseHook function is declared as:
SetWindowsHookEx(WH_MOUSE, MouseHook, NULL,GetCurrentThreadId());
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.
LRESULT CALLBACK MouseHook(int nCode, WPARAM wParam, LPARAM lParam)
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 06:46 PM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!