RESOLVED: Open a 2nd Window

Started by
5 comments, last by Lanky007 17 years, 12 months ago
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]
Advertisement
HWND window1;HWND window2;window1 = CreateWindowEx(...);window2 = CreateWindowEx(...);ShowWindow(window1, SW_SHOW);ShowWindow(window2, SW_SHOW);


Basically, just repeat the process for the existing window.
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.
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.
MSDN: GetSystemMetrics(), GetClientRect()
Use centering formula.
Then again, this is the manual way. If there is another, please post it.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
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.

http://www.winprog.org/tutorial/

i think it has one example at least where it does that

This topic is closed to new replies.

Advertisement