Intercepting mouse clicks when the mouse is hovering above a control - c++

I'm working on a MFC C++ dialog where I need to respond to right mouse click events for a dialog even if the mouse is hovering over a control.
I could write event handler code for each control to delegate the work to the parent dialog, but I'm hoping there is a more elegant solution?
I'm hoping there is some way to intercept the windows messages, but I'm still figuring that part out. I've tried listening to the WM_COMMAND messages with Spy++ but I didn't see what I needed.
Any suggestions?

You could set up a hook to intercept mouse messages. Take a look at SetWindowsHookEx and WH_MOUSE

Related

WM_DRAWITEM get called only when mouse is in dialog window

I'm working on a themed ownerdraw button using Win32 native.
Following a tutorial and a sample project on another website, I got my button almost perfect(almost without bug), but there's one which left, and I have a issue in fixing it.
Basically, I'm subclassing using SetWindowLongPtr API the window of the button, and from there, when WM_LBUTTONUP is catched, I would need to call DrawThemeBackground for reset the state of the button, OR, just handle again WM_DRAWITEM. The problem is that WM_DRAWITEM is getting called only when my mouse is on the dialog window, which is not really a problem, if there would be a way for advice the main dialog to handle it when I want it. I tried with InvalidateRect, but it is not making WM_DRAWITEM, but WM_CTLCOLORBTN.
So, my question is:
Is there any way for let WM_DRAWITEM being handled even if the mouse is out of the dialog
OR
Is there any way for advice the main dialog that it should handle again WM_DRAWITEM, evne if the mouse is out of the dialog?
Thanks alot for taking your time in replyng me.

Detect when a Window has stopped moving?

Does anyone know how to detect if a Win32(c++) window has stopped moving?
WM_MOVE detects when the window is moving, but how does one detect when it has stopped moving?
The windows message you wish to handle is WM_EXITSIZEMOVE.
WM_EXITSIZEMOVE message (Windows) # MSDN
Depending on what you wish to accomplish, there's also the possibility that you might be better served by reacting to WM_NCLBUTTONUP, which is sent when the mouse button is released in the non-client areas of a window, such as the title bar of any window with a caption, border chrome, etc.
WM_NCLBUTTONUP message (Windows) # MSDN

Track mouse over event in Windows CE

How to track the Mouse Over event while moving Mouse over Menu or some other window?
I have tried TrackMouseEvent, But it's not supported by Win CE. Is there any other way?
You can use either the Tooltip control:
MSDN Article about ToolTips in WinCE
Or directly work with the WM_MOUSEMOVE messages and do it yourself. It's not very hard to with mouse messages because you can use the WindowFromPoint() function to know what window you mouse is hovering over.

How to check if a mouse is over a control

How does one check if the mouse is over a certain HWND? I have tried using the WM_MOUSELEAVE and WM_MOUSEMOVE messages to keep track, but if you click a button and drag the mouse out of the button, it doesn't receive the WM_MOUSELEAVE until the mouse is released, which is too late, because:
When you click a button, the WM_COMMAND message is only sent if:
1. The mouse was originally depressed over the button
2. The mouse is over the button
3. The mouse is released over the button
I need to replicate this functionality.
To duplicate this functionality, just call SetCapture() so that mouse messages are sent to your window even if the mouse leaves it. You can read the current mouse position as it moves and determine if it is still over your window/button (I'm still not 100% sure what you are doing). And, when the mouse button is released, you can call ReleaseCapture() to restore where mouse messages are sent.
EDIT: Oh, and you can use the Windows API function WindowFromPoint() to determine which window the mouse is over.
This is built-in to Windows, it is called 'mouse capture', SetCapture(hWnd). It ensures you get mouse messages even though the mouse has moved outside of the window. You call it on the WM_LBUTTONDOWN message notification.

How can we capture a mouse event when it's already out of the client area?

I have an application that has a list of buttons and has customized tooltips. Whenever the mouse hovers through the buttons, the tooltips come out and is working fine. However, I want to hide the tooltips when the mouse cursor is outside the client area. How can I tell my application that the mouse is already out of the client area, when the mouse events I have are limited to the client area alone?
Thanks...
You use TrackMouseEvent, this will send you a WM_MOUSELEAVE message when the mouse leaves your window.
Or use GetCapture(), that's what I always do.