Skip to main content
Topic: Global Mouse Hook (Read 3896 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Global Mouse Hook

I have designed some kind of custom popup menu that I want to close when the user clicks outside of it. To do this right now I'm setting up a global mouse hook with a line of code like this:

SetWindowsHookEx( WH_MOUSE, proc, core_api::get_my_instance(), 0 );

and close the menu in proc after checking that the click is outside menu's bounds. But this doesn't work with clicks outside foobar2000's main window. Am I doing something wrong? generally is this the right way to do such thing?

Any help/idea is welcome, thanks.

Global Mouse Hook

Reply #1
Set capture maybe?
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.

Global Mouse Hook

Reply #2
Set capture maybe?

[quote author=MSDN Library link=msg=0 date=]SetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down.[/quote]
This doesn't seem to do what I want, works only when dragging.

Global Mouse Hook

Reply #3
There's no function for checking if it's lost focus?

Just a thought.
Windows 10 Pro x64 // foobar2000 1.3.10

Global Mouse Hook

Reply #4
Typically context menus disappear properly without any need for manual testing. Are you creating yours in some odd way, maybe forgetting to set a parent or something?
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.

Global Mouse Hook

Reply #5
There's no function for checking if it's lost focus?

yes WM_KILLFOCUS message is sent to the window but firstly the window doesn't always have focus when visible (may be launched when user is typing in an edit box to suggest values) and secondly not every click steals focus (normal context-menus hide even when the click doesn't change the focus).

Typically context menus disappear properly without any need for manual testing. Are you creating yours in some odd way, maybe forgetting to set a parent or something?

This is not a normal context menu it's a window with WS_POPUP and WS_EX_TOOLWINDOW styles that acts like a context menu/drop-down list.

Global Mouse Hook

Reply #6
Windows typically uses modal message loops for this kind of popup. At least that's what TrackPopupMenu does internally. I'm not sure if a drop-down combo box does the same.

Global Mouse Hook

Reply #7
Windows typically uses modal message loops for this kind of popup. At least that's what TrackPopupMenu does internally. I'm not sure if a drop-down combo box does the same.


Yes, what I want to know is what exactly happens in TrackPopupMenu.


Global Mouse Hook

Reply #9
Raymond Chen has written a series of articles on modal message loops, see for example Modality, part 3: The WM_QUIT message.


Well, now that I look at it more closely I don't believe that context-menus and drop-down lists are modal UI elements they don't "lock the user into completing an action" like modal dialog boxes do (When a modal dialog pops up windows doesn't even let you close the application before closing the dialog).

I think getting into the modal/modeless debate makes things more complicated, the question is very straight forward right now "How to effectively detect outside clicks to close the window". Something tells me there should be an easier way to do this than injecting a dll into all running processes by registering a global mouse hook.

Global Mouse Hook

Reply #10
Context/popup menus and drop-down lists are just as modal as dialog boxes in the sense that they affect the way the user input is processed. They require the user to select an item and will display until the user has done so or cancelled them. While they are on screen, they get the first shot at handling mouse and keyboard input. However, they are much easier to cancel than a dialog box.

Global Mouse Hook

Reply #11
You might be right but this debate doesn't really concern me much right now. I just want to know how to close the damn popup window

 
SimplePortal 1.0.0 RC1 © 2008-2019