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.
Related
I have used SetParent(childwindow, parentWindow) to set another window to be a screen in my app. But after my app resizes, this child window can not get any keyboard events.
I know you can create an MDI window to Frame window but what about dialog-based window is it possible to create MDI window to it too or it is just exclusive for Frame window only?
or Is it possible to create an MDI client window then create an MDI child Frame window to dialog-based window?
Can it be done? Probably. Is it a good idea? Probably not.
The main issue is that both MDI and dialogs want to control focus and keyboard handling.
You definitely need to use CreateDialog and not DialogBox to create the main window because you need control of the message loop. TranslateMDISysAccel and IsDialogMessage can help you a little bit but you probably need some custom handling that determines if the active/focused window is a MDI child frame or a normal dialog control and prioritize messages for MDI or the dialog. The most difficult being tabbing out of the MDI child frame window and back into the dialog. The last one you could work around by adding a custom key like F6 to set the focus back to the dialog.
Raymond Chen did a blog post series about dialogs, some of them about how you can write your own dialog class and/or custom dlgproc handling.
Even with full control of the message loop and some control over the dialog, you might still end up having to subclass the dialog and/or the MDI client window to handle specific messages.
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
C++
I have a modal child window that can be launched form a main window. The application runs on a Citrix server and when the user is on dual monitors, she can drag the child window to the secondary display and somehow Windows saves this position. When she moves to a workstation with a single display, she complains that the application is freezing when in reality the child window is off the screen and can be brought to the main display with some key combinations. Is there a way I can programmatically force the child window to always open on the screen where the parent window is located?
You can try calling CWnd::CenterWindow which will just position the window in the centre of the main monitor (usually above the parent window).
You should override PreCreateWindow and modify the the respective entries in the CREATESTRUCT to force the window into the visible area. Guidelines for positioning a window can be found at the MSDN ("Positioning Objects on Multiple Display Monitors").
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.