The window closes, but the process stays open because WM_DESTROY is never received through WndProc so I cannot call PostQuitMessage and break out of the loop by testing for WM_QUIT.
This is the code for processing the messages:
//Message procedure
LRESULT CALLBACK CGameWindow::HandleMessage(UINT Msg, WPARAM wParam, LPARAM lParam){
//Handle stuff, return superclass method
switch(Msg){
case WM_DESTROY:
{
LRESULT ret = this->CWindow::HandleMessage(Msg, wParam, lParam);
PostQuitMessage(0);
return ret;
break;
}
case WM_INPUT:
//Dispatch off to RawInput and we don't care anymore >
//this->pRawInput->ProcessInputs(reinterpret_cast<HRAWINPUT>(lParam));
//MessageBox(this->hWnd, L"Received input message", L"YAY", MB_OK);
return 0;
break;
default:
return this->CWindow::HandleMessage(Msg, wParam, lParam);
}
return this->CWindow::HandleMessage(Msg, wParam, lParam);
}
LRESULT CALLBACK ExtendedWindowsAPI::ExtendedWindows::CWindow::HandleMessage(UINT Msg, WPARAM wParam, LPARAM lParam){
//We will setup vital stuff such as the menu and removing this from CWindowManager
//Upon destruction
switch(Msg){
case WM_CLOSE:
DestroyWindow(this->hWnd);
break;
case WM_DESTROY:
{
//2 cases, this has a parent or this does not have a parent
if(this->pParent == nullptr){
//No parent
//This will always break on error
//Remove from CWindowManager
int WndID = reinterpret_cast<int>(GetPropW(this->hWnd, L"ID")); //ID Stored by pManager->CreateWindow(...)
ExtendedWindowsAPI::ExtendedWindows::CWindowManager* pManager =
reinterpret_cast<ExtendedWindowsAPI::ExtendedWindows::CWindowManager*>(GetPropW(this->hWnd, L"pWindowManager")); //Local, do not use delete
if(!pManager){
//Null checks
this->log(LEVEL_ERROR, "pWindowManager is somehow null");
break;
}
if(!pManager->RemoveWindow(WndID)){
//This is bad...
//Will cause an error in delete pWindowManager?
this->log(LEVEL_ERROR, "Failed to remove a window with id: %d", WndID);
break;
}
//Remove all properties after window manager is done
RemovePropW(this->hWnd, L"pWindowManager");
RemovePropW(this->hWnd, L"ID");
RemovePropW(this->hWnd, L"this");
} else {
//Parent
//Child windows should be destroyed before the parent is destroyed
int WndID = reinterpret_cast<int>(GetPropW(this->hWnd, L"ID")); //ID Stored by pManager->CreateChild(...)
ExtendedWindowsAPI::ExtendedWindows::CChildManager* pManager =
reinterpret_cast<ExtendedWindowsAPI::ExtendedWindows::CChildManager*>(GetPropW(this->hWnd, L"pChildManager")); //Local, do not use delete
//Null checks
if(!pManager){
this->log(LEVEL_ERROR, "pChildManager is somehow null");
break;
}
if(!pManager->RemoveChild(WndID)){
//This is bad...
this->log(LEVEL_ERROR, "Failed to remove a child with id: %d", WndID);
break;
}
//Remove all extra properties
RemovePropW(this->hWnd, L"pChildManager");
RemovePropW(this->hWnd, L"ID");
RemovePropW(this->hWnd, L"this");
}
//Reset window_exists
this->window_exists = false;
//Break and return DefWindowProc(...)
break;
}
default:
return DefWindowProc(this->hWnd, Msg, wParam, lParam);
}
return DefWindowProc(this->hWnd, Msg, wParam, lParam);
}
UPDATE: I set breakpoints within WM_DESTROY, and I am getting the message. I do call PostQuitMessage(0), but testing for WM_QUIT in the message loop seems to always fail.
Message loop:
//run()
int CStemManager::run(){
//Message pump - Game oriented
MSG Msg;
while(TRUE){
//Loop through each message
while(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)){
//Translate and dispatch each message received
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
//Check for quits
if(Msg.message == WM_QUIT){
break;
}
//Do stuff
//this->pGameWindow->run();
}
return static_cast<int>(Msg.wParam);
}