Reputation: 703
I'm trying to destroy the HWND I'm currently using, and open up a new window...
this is my code :
PostMessage(MainHwnd, WM_DESTROY, NULL, NULL); // Destroy the window
getClient() -> StartClient(); // Opening the client
where in StartClient I have:
RegisterMainClass(MainInstance); // Registaring the class
//Creating the Window
MainHwnd = CreateWindowEx(WS_EX_CLIENTEDGE ,"MainClient", "Client", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 600, 500, NULL, NULL, MainInstance, NULL);
ShowWindow(MainHwnd, SW_SHOW);
UpdateWindow(MainHwnd);
So the window is destroyed, and the Client window shows up.. but the client window only shows up for about a second, and then dissapears again! Why is that? I have checked it couple of times, it actually creates the client window well, but it somehow hides it...
Also, I've checked with the WndProc of the Client Window,and it does reach the line of return DefWindowProc(hwnd, msg, wParam, lParam);
So what is going on? why is the window dissapearing right away?
I also have those 2 sections in my RoomProc :
case WM_CLOSE:
PostQuitMessage(1);
break;
case WM_DESTROY:
DestroyWindow(hwnd);
Upvotes: 0
Views: 88
Reputation: 703
I've used both lines (destroying the window and create a new window) inside a thread, and therefor, it did problems to me. once I called the function normally and not in a different thread, everything went smooth...
Upvotes: 0
Reputation: 595320
Don't post WM_DESTROY
manually. Use DestroyWindow()
instead:
//PostMessage(MainHwnd, WM_DESTROY, NULL, NULL);
DestroyWindow(MainHwnd); // Destroy the window
Since you are going through the message queue, your WM_DESTROY
message is delayed until new messages are processed at a later time, but by then your MainHwnd
variable has changed value to point at the new window. Besides, posting WM_DESTROY
does not actually destroy the window, it merely notifies the window that it is being destroyed.
Upvotes: 2