hello everyone.
i am making a program which has multiple windows.
how do I program that when one parent window pops-up, the other parent window closes?
i am using Microsoft visual studio 2010, in a Win32 application.
i am not using a windows form.
when I used that, all windows closed and the application ended.
here is the bit of the code, hMainMenu is the HWND of the window whitch needs to be destroyed.
Simple fix. Add a boolean control variable that controls whether POstQuitMessage() is called. Basically, if you are closing the window because you are creating a new one, don't post the quit message.
I'm posting the code I would initially use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//This declaration goes at the beginning of the Window Procedure:
staticbool bDontQuit = false;
//Then inside the if (hMainMenu) block:
bDontQuit = true;
SendMessage(hMainMenu, WM_CLOSE, 0, NULL);
hMainMenu = hWnd;
//Then in the block for WM_DESTROY:
if (!bDontQuit)
{
PostQuitMessage(0); //You don't pass WM_QUIT here. You pass whatever number you want to return as exit code for the process. Usually 0 means "normal exit".
}
bDontQuit = false;
break;
EDIT: As I read this, I realize that I should have used a variable called bYesQuit. :-P It would have been simpler to understand, hehe. Your choice.
case WM_CREATE:
if (hMainMenu)
{
bDontQuit = true;
SendMessage(hMainMenu, WM_CLOSE, 0, NULL);
}
hMainMenu = hWnd;
break;
How I tested: Using VS 2008 Pro, I created a new Win32 project. I allowed the project to have the basic Win32 app skeleton VS provides. I added a New Window menu item, I separated the window creation logic from InitInstance() into a separate function and then called that function on the menu click (WM_COMMAND). The code works fine.