How can I capture the window quit message?
In the following code, I want to capture the window quit or close message. but I cannot get it using the following code. How can I do?
Thanks.
void CEx1Dlg::OnStart2()
{
// TODO: Add your control notification handler code here
int i = 0;
BOOL ret;
MSG msg;
while(1)
{
ret = ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
if(ret)
{
if((msg.message == WM_QUIT) || (msg.message == WM_DESTROY) || (msg.message == WM_CLOSE))
{
AfxMessageBox("Quit message received!");
break;
}
TRACE("MSG :%d\n", msg.message);
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
i++;
}
}
Re: How can I capture the window quit message?
Why you capture the message in your OnStart2()
function,you can override the window's WndProc()
function,in it you can judge the message.Try it,
you will find it works.