在Windows编程中,关于消息处理中的GetMessage,MSDN中有如下描述:

The GetMessage function retrieves a message from the calling thread's message queue and places it in the specified structure. This function can retrieve both messages associated with a specified window and thread messages posted via the PostThreadMessage function. The function retrieves messages that lie within a specified range of message values. GetMessage does not retrieve messages for windows that belong to other threads or applications.

程序通过GetMesage从呼叫线程的消息队列中取出一条一条的消息。

BOOL GetMessage(
  LPMSG lpMsg,         // address of structure with message
  HWND hWnd,           // handle of window
  UINT wMsgFilterMin,  // first message
  UINT wMsgFilterMax   // last message
);


其中第二个参数是窗口句柄。

hWnd


Value

Meaning

NULL

GetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread via PostThreadMessage.


 

在具体尝试中,出现了如下情形:

情形1(以下是部分关于消息处理的

...........
MSG msg;
 while(GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 } ..........
 case WM_CLOSE:
  if( IDYES==MessageBox(hwnd,"就这样结束?","Wave-p",MB_YESNO) )
  {
   DestroyWindow(hwnd);
  }  
  break;
 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 default:
  return DefWindowProc(hwnd,uMsg,wParam,lParam);............

情形2:

将情形1中的 while(GetMessage(&msg,NULL,0,0))
变成     while(GetMessage(&msg,hwnd0,0))          

执行程序过程中,生成可执行文件test.exe对比出现问题:

当关闭窗口时,弹出对话框“就这样结束?”选择“是”,窗口关闭。

在情形1下,打开任务管理器(task manager)的进程(process)会发现,关闭之前test.exe的CPU占用率是0%,内存使用是2840k,关闭之后test.exe会自动结束(end process)。

在情形2下,关闭之前test.exe的CPU占用率是0%,内存使用是2868k,关闭之后test.exe依然存在,没有自动结束,而且CPU 使用率是98%,内存占用是2980K。

请问:这是什么原因?