MFC Unclickable Button (Running away from cursor on MouseMove) - c++

How would i make a button that will change it's position on MouseMove Event if the cursor is close enough to the center of the button in MFC ?

WM_MOUSEMOVE is not delivered to the button if the cursor is not over it (and is not captured, but you don't want that). So you have to process WM_MOUSEMOVE in the parent dialog. If you want your button to be a self-contained control, you have to subclass the parent window upon button creation.
Subclassing, in this context, means:
- you retrieve and store the parent's window proc address with GetParent()->GetWindowLong(GWL_WNDPROC)
- you set it to your procedure with SetWindowLong()
- in the procedure, you call the parent's previous window proc, after handling WM_MOUSEMOVE the way you want.

The WM_MOUSEMOVE coordinates will be relative to the screen, but you'll probably want to track the button position relative to the window that contains it. Use the ScreenToClient method on the parent window to convert, then you can compare the coordinates to see if it's close. Then use MoveWindow to move the button.

If you track the mouse cursor position you can determine when the cursor gets close to or enters the button window rect. You can then use the SetWindowPos() function to reposition the button window in the parent window client area.

Related

How to detect mouse click on the entire window?

I want to check if the mouse button is clicked or released on my window in order to change the cursor. For now I have the signals, connected to the main window, but the problem is that , when I hover my mouse cursor over the button or GLArea, the events I linked to the window do not work, so the cursor does not change. By the way, all buttons in my application have their own signals, so, to change the cursor state I should duplicate the function below for all widgets, which does not seem good.
window->signal_button_release_event().connect(sigc::bind(sigc::ptr_fun(&MouseBtnReleased), window));
window->signal_button_press_event().connect(sigc::bind(sigc::ptr_fun(&MouseBtnClicked), window));

Allow clicks to pass through window(hit-test transparency) on a non-transparent window

I have a layered window that I want all clicks to pass through no matter where the mouse is located. Some parts of it are color keyed, and others are not. Clicks pass through the window whenever the mouse is on a transparent part but whenever the mouse is on a non-transparent part, the window captures the click. An easy solution would be just to add the WS_EX_TRANSPARENT flag to the window but I DO NOT want to do that. I tried returning -1 on WM_NCHITTEST in WndProc since WM_NCHITTEST is called every time the mouse enters a non-transparent zone but that didn't work and clicks still didn't pass through non-color keyed areas of the window.
Thanks in advance

About sub control's response after SetCapture() in parent window

I create a window in a view and create a scrollbar control in that window.
The window has edit mode. In edit mode, it will call SetCapture() and all the mouse event messages are sent to the window. So the other windows in that view will be disabled and have no chance for mouse operation in edit mode.
But it causes the following problem:
- In edit mode, mouse operation in Scrollbar makes no response. Because of SetCapture() to parent window.
So how can I SetCapture() a window but make the sub control respond to mouse operation?
SetCapture must not be called outside WM_*BUTTONDOWN. Read the documentation!

How to get the window position and update to other windows?

I have 2 dialog boxes in which I will display 1 dialogbox at a time..If I click NEXT in the first dialog box,I will hide the first dialog box and display the second dialog and vice versa...Now say If I move the dialog box after clicking NEXT in the first dialog..and when I click BACK(in the second dialog) ...it goes back to its previous position(to diaplay the first dialog box)..so I have decided to get the current window's position and update to the other window position so that it doesnt move even If I click next/back..I am not sure how to get the windows position and update to other..please help me if you guys know about this..
You can create an OnMove handler for WM_MOVE messages to detect when your window moves. In the handler, you can either move the other window directly with MoveWindow, or you can send a private message to the window (something in the WM_APP range would be best) and let it move itself. Use GetWindowRect to get the width and height to pass to MoveWindow.

How to prevent the mouse cursor from being hidden after calling CComboBox::ShowDropDown?

In my MFC application, when I call CComboBox::ShowDropDown(), the mouse cursor is hidden until interaction with the combo box completes (when the combo box loses focus.) It doesn't reappear when the mouse is moved, like it does with edit boxes.
How can I keep the mouse cursor from being hidden?
Call
SetCursor(LoadCursor(NULL, IDC_ARROW));
immediately after the ShowDropDown() call.