   D3D keeps running after I've terminated the thread + released the D3D stuff?
  I noticed I got the error from D3D9:Direct3D9: (ERROR) :GetClientRect Failed ?It was trying to call LPDIRECT3DDEVICE9's function Present(); But my window has terminated.I have a function called Main() that looks like thisvoid Main(){InitGame();//Main loopwhile(MsgCheck()){Input();Logic();Render();}QuitGame();return;}Which is called from WinMain(). MsgCheck looks like thisbool MsgCheck(){while(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE)){if(msg.message==WM_QUIT)return false;TranslateMessage(&msg);DispatchMessage(&msg);}return true;}If I press the X button in the right cornor of the window, shouldn't it send a WM_QUIT message to the window and then it checks for WM_QUIT in the MsgCheck() function and if the message is WM_QUIT it returns false which causes the loop in Main() to fail thus running QuitGame() ? Where am I wrong?   
  What does your message handler look like?  When you close a window, you don't get WM_QUIT right away.  You first get WM_CLOSE to indicate that the window is closing.  If you pass it through to DefWindowProc, it will call DestroyWindow to destroy the window.  If you don't call DefWindowProc, you'll have to do it yourself.Once DestroyWindow is called, the window is actually destroyed.  When this happens, you get the WM_DESTROY to indicate that your window is being destroyed.  If you want your app to quit at this point, then you need to call PostQuitMessage(0) to indicate that your message loop should terminate.  Only then will you get the WM_QUIT message you're waiting for.   ;  I think I need to fix my message handler, but I've got a bad headache so I'll do it tomorrow, thanks a lot!   