Click here to Skip to main content
13,092,862 members (74,402 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a small thread that I need to terminate when I send WM_CLOSE to it . I am following the MSDN directives to deal with this problem , that is I set the wnd procedure of the thread like this:

WndProc :

case WM_CLOSE: DestroyWindow(hWnd);
case WM_DESTROY : PostQuitmessage(0);
return 0;

I expect the DestroyWindow(hWnd) to send WM_DESTROY to the same thread, which I manage by calling the PostQuitmessage(0) which should cause the message loop of the thread 's window to exit, that is the thread to terminate.

but what I see is, quite surprisingly, the wnd proc receives the WM_DESTROY before (and not after, as I expected) the DestroyWindow(hWnd) is called.
I am 100% sure there is no such thing as SendMessage(hWnd, WM_DESTROY,...) nor PostMessage(hWnd, WM_DESTROY, ..) around the application.
Nor is there any overriding of window handles anywere (I log any handle before using it and I never detected any undue variation of such handles).
How is it possible ?
What's even stranger is : I know, because I log almost everything, that I correctly get to DestroyWindow(hWnd) (after receiving WM_CLOSE) and that this function call succeeds, that is it returns nonzero. But this always happens a bunch of nanoseconds after receiving that misterious WM_DESTROY. After calling DestroyWindow(), no more WM_DESTROY seems to be sent....
Posted 30-Apr-13 0:30am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100