Sign in to follow this  
CTEagle

RESOLVED: Open a 2nd Window

Recommended Posts

Through some tutorial on this site and others, I have learned how to open a window in a C++ Win32 application and I think I have a pretty decent handle on how to do that. I have not been able to figure out how to open a 2nd window with it's own set of buttons, textboxes, etc. I am not using MFC and I do not want a MDI child window. If someone could point me to a good tutorial that covers creating and destroying windows based on user actions, I would greatly appreciate it. Thank you in advance. [Edited by - CTEagle on April 25, 2006 10:37:56 PM]

Share this post


Link to post
Share on other sites
Creating a second window is the same process as creating the first. Where to create the second window really depends on what you're doing with it and how it is supposed to interact with the rest of the application.

For example, if you had an options dialog as your second window and you needed the user to complete the dialog before interacting with the main window then you would use DialogBox() within the message loop of the main window. That is


LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
// *snip* cases we dont care about

case WM_COMMAND:
switch (LOWORD(wParam)) {
// *snip* cases we dont care about
case IDM_OPTIONS:
DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_OPTIONS_DIALOG), hwnd, OptionsProc);
break;
}
break;

// *snip
}

return 0;
}



If you are able to have the user interact with both windows at once you can simply create the window using CreateDialog() or CreateWindowEx() and you main message pump using GetMessage() should handle it appropriately.

Share this post


Link to post
Share on other sites
Thanks to both of you for taking the time to respond. Both of your answers got me going in the right direction. I am now able to open new windows based on user activity.

The only thing I cannot do is center the windows on the screen. Could someone point me to an example of how this is done?

Thanks in advance.

Share this post


Link to post
Share on other sites
Thanks deadimp.

I was able to center my windows by using SM_CXSCREEN and SM_CYSCREEN values returned by the GetSystemMetrics() function along with the values returned by GetClientRect().

Thanks for pointing me in the right direction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this