Windows编程非典型错误

 最近在做Windows编程,动手的时候有些小问题,贴在这里以免重复犯错.

编译通过,运行时貌似正常。可问题在于当单击标题栏右上角的关闭按钮时,虽然整个页面会被关闭,可是该进程却并没有被消灭,在任务管理器中仍旧能看到。

经过和某些范例的比较,终于发现问题出现在GetMessage(&msg, hwnd, 0, 0)这个语句中的第二个变量上。

MSDN中关于此变量的解释为:

 

hWnd [in, optional]

Type: HWND

        

A handle to the window whose messages are to be retrieved. The window must belong to the current thread.

If hWnd is NULL, GetMessage retrieves messages for any window that belongs to the current thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG structure). Therefore if hWnd is NULL, both window messages and thread messages are processed.

          If hWnd is -1, GetMessage retrieves only messages on the current thread's message queue whose hwnd value is NULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) or PostThreadMessage.

 

         <Programming Windows> Chapter 3 describes what will happen when you click Close button in your program.

        Sometimes messages generate other message as a result of DefWindowProc processing. For example, suppose you eventually click the Close button, DefWindowProc processes this mouse input. When it detects that you have selected the Close option, it sends a WM_SYSCOMMAND message to the window procedure. WndProc passes this message to DefWindowProc. DefWindowProc responds by sending a WM_CLOSE message to the window procedure. WndProc again passes this message to DefWindowProc. DefWindowProc responds to the WM_CLOSE message by calling DestroyWindow. DestroyWindow causes Windows to send a WM_DESTROY message to the window procedure. WndProc finally responds to this message by calling PostQuitMesage to put a WM_QUIT message in the message queue. This message causes the message loop in WinMain to terminate and the program to end.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值