妳應該檢測WM_DESTROY或者WM_CLOSE,根據妳的需要應該是檢測WM_DESTROY
點小叉叉所引發的消息鏈是這樣的:
點叉叉,收到壹個WM_CLOSE消息,壹般這個消息自己不處理,所以送入DefWindowProc,默認的WM_CLOSE處理是送出壹個WM_DESTROY消息,然後妳收到,這個時候的壹般處理是PostQuitMessage,送出壹個WM_QUIT消息,GetMessage收到WM_QUIT就返回0,所以while就直接結束了,接下來的邏輯無法完成。
這是MSDN上對GetMessage返回值的解釋:
Return
Value
If
the
function
retrieves
a
message
other
than
WM_QUIT,
the
return
value
is
nonzero.
If
the
function
retrieves
the
WM_QUIT
message,
the
return
value
is
zero.
If
there
is
an
error,
the
return
value
is
-1.
For
example,
the
function
fails
if
hWnd
is
an
invalid
window
handle
or
lpMsg
is
an
invalid
pointer.
To
get
extended
error
information,
call
GetLastError.