| | |
DestroyWindow
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I am kind of confused about how DestroyWindow() works. According to the help files this function sends a WM_DESTROY message to the window it has just removed from the screen. In my
But when I close the window it gets removed from the screen alright, but I can still see it from my task manager. Should not DestroyWindow() send a WM_DESTROY message, which according to the code above would activate PostQuitMessage(0) (aka WM_QUIT) . So I was expecting my program to end completely.
Let me know if I am getting it wrong.
WindowProc I have something like the following: C++ Syntax (Toggle Plain Text)
case WM_CLOSE: { DestroyWindow(hwnd); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; }
But when I close the window it gets removed from the screen alright, but I can still see it from my task manager. Should not DestroyWindow() send a WM_DESTROY message, which according to the code above would activate PostQuitMessage(0) (aka WM_QUIT) . So I was expecting my program to end completely.
Let me know if I am getting it wrong.
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
PostQuitMessage() only posts a WM_QUIT message to the message loop. The message loop may or may not receive the WM_QUIT message as soon as the PostQuitMesasge(0) is called. Also as DestroyWindow does the destroying of the child windows, resources ...blah blah, there maybe a delay in that too. But I don't think it should take more than a couple of seconds. So the reason may depend on the delay you are experiencing. If it is only a small delay, then the reason must be what I explained. If not, then there must be resources still allocated to the calling thread.
Let me comment on the
WM_CLOSE message also. I see that you are explicitly calling DestroyWindow at the WM_CLOSE message. This is unnecessary. If you just let the DefWindowProc handle it, it will automatically call the WM_DESTROY Message. So either you can remove the WM_CLOSE message handling part from the message loop ( if all that you do is call DestroyWindow() ) //case WM_CLOSE: Removed the WM_CLOSE handling
//
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam) ;just insert a break like this.
case WM_CLOSE:
{
// Do the user notification and whatever else you want to do
//DestroyWindow(hwnd); // Commented out this function call
break; // break to the DefWindowProc function
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam) ; バルサミコ酢やっぱいらへんで
I need to do certain things when user tries to close the window. Say may be to ask him whether he actually wants to quit or not etc. That's why I cant let DefWindowProc() to handle it. But that was not the point. According to what I know the flow should be like this
WM_CLOSE > DestroyWindow() > WM_DESTROY > WM_QUIT(via PostQuitMessage).
After this I didn't expect to see the file in the task manager(consequently I cannot compile my program the second time bcos the file is still used by windows ).
As for the delay for PostQuitMessage() I always have to end the program through my task manager otherwise it stays there forever.
WM_CLOSE > DestroyWindow() > WM_DESTROY > WM_QUIT(via PostQuitMessage).
After this I didn't expect to see the file in the task manager(consequently I cannot compile my program the second time bcos the file is still used by windows ).
As for the delay for PostQuitMessage() I always have to end the program through my task manager otherwise it stays there forever.
"He who mixes with people and endures the harm they do is better than he who does not mix and endures." (Tirmidhi)
•
•
•
•
Originally Posted by Asif_NSU
I need to do certain things when user tries to close the window. Say may be to ask him whether he actually wants to quit or not etc. That's why I cant let DefWindowProc() to handle it.
•
•
•
•
Originally Posted by Asif_NSU
But that was not the point. According to what I know the flow should be like this
WM_CLOSE > DestroyWindow() > WM_DESTROY > WM_QUIT(via PostQuitMessage). After this I didn't expect to see the file in the task manager(consequently I cannot compile my program the second time bcos the file is still used by windows ). As for the delay for PostQuitMessage() I always have to end the program through my task manager otherwise it stays there forever.
バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- Image Not Showing (C)
- graphic.h (Game Development)
- Visual C++ program compiles, but won't run (C++)
- Displaying a different bitmap in different child windows? - win32 in C (C)
- Need help with DirectX code (C)
- GDI (C)
Other Threads in the C++ Forum
- Previous Thread: Cubic equation
- Next Thread: Some problems while compiling unidrv with another library
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






