讨论:GetMessage()的第二个参数使用

在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
Handle to the window whose messages are to be retrieved. One value has a special meaning:
ValueMeaning
NULLGetMessage 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。

请问:这是什么原因?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路漫漫其修远.

你的鼓励是我寻找真相的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值