Try changing your msg loop to:
Code:
while (GetMessage(&Msg,NULL,0,0))
{
/*first check if the message is from a resource defined keyboard accelerator key*/
//if (!TranslateAccelerator(hwnd,hAccelTable,&Msg))
{
/*now check for default dlg keyboard keys eg TAB, ESC*/
if ((!IsWindow(hwnd))||(!IsDialogMessage(hwnd,&Msg)))
{
/*translate and dispatch other messages*/
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}
You will need to add additional code your WM_COMMAND handler to check for the ESC key being pressed or the wnd close btn; the handler will receive IDCANCEL (system defined) as the LOWORD(wParam) ie the id.