I'm not sure if I put my stuff correctly in the message loop(Render()):
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(!Graphics::Obj().Render())
{
MessageBox(NULL, "Failed to render", "Error", MB_OK | MB_ICONEXCLAMATION);
break;
}
}becouse when I close the window I get an error from the MessageBox function above. Probably becouse when I'm handling messages before rendering the window is firstly destroyed and then DirectX doesn't have a window to draw on. When I put my Render() function above translating and dispatching messages I don't get the error, but mostly people advise to handle messages before doing anything else?This is how I'm handling messages to close window:
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_CLOSE:
DestroyWindow( hwnd );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
//...
default:
return DefWindowProc( hwnd, msg, wParam, lParam );
}
return 0;
}