Child window freeze if opened during parent window resize - c++

I have some window. User can drag it, resize etc. At some point there can be a message that should be shown in modal window. I'm creating such a window as child and setting parent window to disabled. Everything works ok except the case when I'm dragging a parent window during the child creation. I used spy to see messages and found that in that case my child window doesn't receives WM_ENTERSIZEMOVE message. It seems that parent's WM_ENTERSIZEMOVE blocks one for child. I tried to manually send WM_EXITSIZEMOVE for the parent but unfortunatelly this doesn't works.

Send the WM_CANCELMODE message to your parent window before displaying the dialog box.
Sent to cancel certain modes, such as mouse capture. For example, the
system sends this message to the active window when a dialog box or
message box is displayed. Certain functions also send this message
explicitly to the specified window regardless of whether it is the
active window. For example, the EnableWindow function sends this
message when disabling the specified window

Related

Child window loses focus after MessageBox is displayed

So i have created a main window inside of which i have created a 2 child windows. They all have different WindowProcs. At the WM_CREATE message of the main window I am giving focus to one of the child windows with SetFocus(...). After I display a MessageBox from the child window proc the focus is set back to main window. How can I maintain focus on the child window?
When the message box window is destroyed, Windows makes another top-level window the active window. If that’s not what you want, it is up to you to respond to the WM_SETFOCUS message that your main (top-level) window will receive and use SetFocus() to direct the focus to the child.

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!

Capturing WM_MOUSEMOVE events in parent window

I have a (parent) window in which a child-window is created by a another library (Ogre3d). Window initialization uses the bare Win32 API.
I'd like to capture the mouse input in my parent window, but it seems like I my WM_MOUSEMOVE events are received only by the child-window, which makes sense, since that fills all of my client-area.
Is there a way to capture the WM_MOUSEMOVE messages in the parent window or (unintrusively) redirect those messages from the child-window?
If you can obtain a handle to the window in question you can subclass it.
In a nutshell, you get to register a callback function that gets a crack at all of the messages sent to the sub-classed window.
The linked article should get you where you need to be.

Class(Child window )destructor not getting called

I have created a window which has a toolbar with some icons, and I launch one more window clicking on the available icon from the main window.
First window is created using CreateWindowEx method.
the one I click using an icon is created using dialog resource.
So without closing dialog, I directly close the main window. I see that dialog window is not getting closed.
When I debug, control does not come to destructor of second window.
When I close them individually (i.e dialog first) and then main window next,then everything is fine.
Please help,that what might be missing when I close the main window.
I mean class desctructor is not getting called.
Handle your main window's message WM_CLOSE and check, whether the dialog window is open or not. If dialog window is open, just close it using the handle you got returned while loading it from resources.

capture the last WM_SIZE

When I resize my window I want to tell another part of my program that my window has changed size. I read on MSDN that:
WM SIZE Message
The WM SIZE message is sent to a window after its size has changed.
However, I receive the WM_SIZE even when dragging.
I noticed that there is also a WM_SIZING message that is sent when my window is resizing. At the moment I do not see the difference between WM_SIZE and WM_SIZING.
Is there some way I can capture the very last WM_SIZE message, as to not "spam" my program with resize messages?
When you start dragging a window, the system enters a modal move/resize loop; it does not return to your own message loop until the drag action has finished. You are still getting WM_SIZE because it is sent directly to the window procedure, but it does not flow through your own message loop.
At the beginning of such a modal drag action, the system sends WM_ENTERSIZEMOVE to your window procedure. When you release the mouse button, your application will get WM_EXITSIZEMOVE. That is probably the message you want to trigger on.
I have observed this pattern:
WM_ENTERSIZEMOVE
Zero or more groups of:
WM_SIZING
WM_SIZE
WM_EXITSIZEMOVE
WM_SIZING doc says:
lParam
A pointer to a RECT structure with the screen coordinates of the drag
rectangle. To change the size or position of the drag rectangle, an
application must change the members of this structure.
Credit to this blog post: https://billthefarmer.github.io/blog/post/handling-resizing-in-windows/
I have a windows app where I want the app window to maintain it’s
aspect ratio when it is resized. Windows provides two mechanisms for
this, the WM_SIZE message and the WM_SIZING message. The WM_SIZE
message is sent when a window has been resized to allow child windows
to be resized, the WM_SIZING message is sent while the user is
resizing it to allow the size to be adjusted. The messages are handled
in the WindowProc callback function.
Also, WM_SIZING provides:
wParam
The edge of the window that is being sized.
Ideas about capturing the last WM_SIZE message:
On each WM_SIZE, save whatever details you need into a global variable (or user data pointer associated with window handle). On WM_EXITSIZEMOVE, use last WM_SIZE details from global var.
On WM_EXITSIZEMOVE, call GetWindowRect() or GetClientRect() depending upon your needs.
I am sure #1 will work, but I did not test #2.