   WM_CLOSE, WM_DESTROY..am I doing this correctly?
  I have a typical D3D Win32 game setup.What I need to do is correctly handle ALT+F4 keypresses to close the application at any point the user desires by pressing the keys. I'd also like a way to add a "quit" command to my ingame quake style console.Here's what I'm doing:global BOOL called bRunning (it's a mix of C and C++ code...) set to TRUE on application start.My main loop is set up to basically do a "while (gameDoingStuff && bRunning)"under this loop, I do my cleanup stuff like release sound, textures and d3d etc.In my WindowProc function, I have:case WM_CLOSE:{bRunning = FALSE;return 0;}case WM_DESTROY:{   PostQuitMessage(0);break;}So, when WM_CLOSE is received, set my bRunning global to FALSE, then return from the WindowProc function to avoid calling DefWindowProc which I believe will destroy the window (which I dont want yet)Then my game loop runs again, realises bRunning is FALSE, skips down to the cleanup code and the app exits.It seems to work fine, but I have my doubts that i'm doing this the "best" way.Can anyone offer any advice please?   
  There may be better ways of doing it (although seeing as you are using native Win32 API your choices are limited), but what you have their looks fine to me.Check out the MSDN docs on Destroying a Window for a description of how to use WM_CLOSE and WM_DESTROY.   ;  Why bother handling WM_CLOSE at all? If you handle WM_DESTROY and get it to post a quit message, you can just check for WM_QUIT in your message loop and break out of it from there.From memory... Something like this...MSG msg;bool running;while(true){    while(::PeekMessage(&msg,0,0,PM_REMOVE)    {   if(msg.message == WM_QUIT)   {  running = false;  break;   } ::TranslateMessage(&msg);   ::DispatchMessage(&msg);    }    DoYourGameStuffHere();}CleanUp();;  Thanks guys, i'll look at that information :)I like the idea of bailing out if a quit message is received in my Peek Message loop. Might make for some cleaner code!   ;  WM_DESTROY is sent by DestroyWindow before it returns.You can just provide an empty handler that returns zero.And to PostQuitMessage(0) within your WM_CLOSE instead.By default the DefWindowProc calls DestroyWindow whenit receives a WM_CLOSE message and you want different:)I learned a good deal of how win messages work by firstcreating a file in which every time a message is foundby PeekMessage/GetMessage it is written to the file.Then (a short time) later you can see what happened.To recap:Use the message pump provided by Neilo in prev post...Then...case WM_CLOSE:   PostQuitMessage(0);   return 0;case WM_DESTROY:   return 0;Handling the WM_DESTROY may seem redundant since the pump is not runningbut remember, internally that SendMessage is used to access the callback...   ;  What is the problem with destroying the window in WM_CLOSE? My guess is that you want to release all D3D objects before destroying the window, but is there a reason for it?I'm asking, because my experience (with DX11; I don't know what you are using) is that destroying the window before releasing D3D objects works fine. But maybe I'm wrong, and my code might break in some cases that I haven't tested yet.   