winapi - how to detect a mouse move over a context menu - winapi

I have created a custom context menu using MFT_OWNERDRAW flag and handling WM_MEASUREITEM and WM_DRAWITEM messages:
I would like to detect when a mouse cursor is over a color square in the context menu. It looks like that I can't subclass HMENU and receive WM_MOUSEMOVE event. How to detect a mouse move over a context menu ?

Related

Get CBN_SELCHANGE notification when combo box item is changed on mouse hover

Is there any notification message for WinAPI combo box controls we can use to know when the current item is changed while moving the mouse pointer over the drop-down list box?
My expectation is that the CBN_SELCHANGE notification should work for the mouse too, but unfortunately it is sent only when we change the selection using the keyboard or click an item with the mouse.
Listen for WM_DRAWITEM in your WndProc, and use the DRAWITEMSTRUCT to determine the selection.

Detect mouse right ckick on combobox

How to detect a mouse click (or mousedown) event on a simple dropdown combo (combobox with style=1)?
I am unable to see mouseclick or mousedown event handlers for combobox in my vb6 IDE.
My aim is to detect right click.
Thanks in advance.
If the events aren't exposed, you may need to subclass the control and handle the WM_RBUTTONDOWN message.

MFC OnMouseActivate: Where is focus if you eat the mouse event?

Where does focus remain?
Is focus left on the window that previously held focus, or is focus in limbo, on no window?
I've noticed that when I eat a message, it appears as if nothing has focus.
I return MA_NOACTIVATEANDEAT
The focus can't be in limbo. Something always has to have the focus, so it will either be the window that previously held the focus, or the new window that is activated by the mouse event.
The documentation for CWnd::OnMouseActivate tells us what will happen, depending on the value that you return from the function:
MA_ACTIVATE Activate CWnd object
MA_NOACTIVATE Do not activate CWnd object
MA_ACTIVATEANDEAT Activate CWnd object and discard the mouse event
MA_NOACTIVATEANDEAT Do not activate CWnd object and discard the mouse event
Since you're returning MA_NOACTIVATEANDEAT, the previously focused object will retain the focus and the mouse event will be discarded.

combobox dropdown window can show beyond the combobox window,how?

in windows, how can make a 'child' window beyond the parent window, and the parent window always in active status (GetActiveWindow() return parent), just like the combobox dropdown window.
I think these are the main points when trying to do this:
The pop-up is a top-level window which has the same parent as the control. (i.e. The pop-up is not a child of the control. It's not a child-window at all; it's a top-level window, but one without a thick window border etc. so it doesn't look like a normal top-level window.) That's why it can extend outside of the control's boundaries.
When the pop-up is created it is shown using ShowWindow(hWndPopup, SW_SHOWNA) so that it does not take the input focus. This prevents the parent window from going inactive.
When the pop-up is created you capture the mouse using SetCapture. You then track where the mouse is and highlight items within the pop-up when the mouse overlaps them. When the mouse button is clicked you act on whatever is under the mouse (or cancel the pop-up if the mouse isn't over it at all). Remember to respond to WM_CAPTURECHANGED, in case something else captures the mouse. And remember to ReleaseCapture when you are done.
The popup should handle WM_MOUSEACTIVATE by returning MA_NOACTIVATEANDEAT.

Getting a borderless window to receive mouseMoved events (Cocoa OSX)

I have a little popup window used for selecting images sorted by groups, and I would like to add a selection box around whatever image is being hovered over. I am trying to this by overriding the mouseMoved event for the window but it seems that a window that has a border-less style mask receives no mouseMoved events even if you have set setAcceptsMouseMoved events to YES. Is there anyway to make a borderless window receive this events?
You need to allow the window to become the key window. By default, borderless windows cannot become key. Subclass NSWindow and override -canBecomeKeyWindow:
- (BOOL)canBecomeKeyWindow
{
return YES;
}
Aternatively, you can use an NSTrackingArea to do your mouse tracking, which may be easier/better anyway.

Resources