当前位置:网站首页>对话框管理器第六章:消息循环中的细节
对话框管理器第六章:消息循环中的细节
2022-08-08 18:56:00 【拓扑梅尔-漫漫开发路】
在上一篇文章中,我留下了一道课后作业:找到EndManualModalDialog和模态对话框消息循环之间的细微Bug。
微妙之处在于:EndManualModalDialog会在内部设置了一些标志,但没有强制消息循环注意到该标志已实际设置。回想一下,GetMessage函数在投递性消息(Posted Message)到达消息队列之前不会返回。 如果传入的已发送消息到达,则将它们传递到相应的窗口过程,但GetMessage函数不返回。 它只是不断传递传入的已发送消息,直到投递性消息最终到达。
因此,Bug是:当你调用EndManualModalDialog时,它会设置指示模式消息循环停止运行的标志,但不会做任何事情来确保模式消息循环会检测这个标志。 在发布的消息到达之前什么都不会发生,这会导致GetMessage返回。 发送消息并重新启动while循环,此时代码最终注意到fEnded标志已设置并跳出模式消息循环。
有几种方法可以解决这个问题。比较快速的方法是:发布一条毫无意义的消息,如下图所示:
这将强制GetMessage返回,因为我们确保队列中至少有一条消息等待处理。 我们选择了 WM_NULL消息,因为它什么都不做。 我们对消息的作用不感兴趣,只对消息存在的事实感兴趣。
最后
Raymond Chen的《The Old New Thing》是我非常喜欢的博客之一,里面有很多关于Windows的小知识,对于广大Windows平台开发者来说,确实十分有帮助。
本文来自:《The dialog manager, part 6: Subtleties in message loops》
边栏推荐
- 一起了解分层架构&SOA架构
- 浅谈C语言简单实现二分查找
- How to add F4 Value Help to the input parameters of the report in the ABAP report
- Learn about layered architecture & SOA architecture together
- 最长子串(长沙理工大学第十一届程序设计竞赛 离线 做了n天.....崩溃了)
- Ability in general, but it can be large horizontal jump freely?Where is the better?
- APICloud AVM 封装日期和时间选择组件
- 干货技巧|如何用3DsMax制作笔记本电脑
- Oracle--表
- 十六、一起学习Lua 文件 I/O
猜你喜欢
随机推荐
How to add F4 Value Help trial version to the input parameters of the report in the ABAP report
leetcode 240.搜索二维矩阵II 分治思想
Vue program of web cache problem after packaging
Implement the entire process of Mock API with tools
使用 lua 运行 fscript
Architecture Design Fundamentals
01. Preface
oracle视图v$active_session_history,dba_hist_active_session_history如何记录IP地址
Will ODPS spark on Dataworks process data more efficiently than directly using ODPS SQL?
阿里云数据库PolarDB开源人才培养计划发布!万元好礼等你来拿!
MogDB study notes - starting from 0
软件测试主要是做什么的?
ABAP 报表中如何给报表的输入参数增添 F4 Value Help 试读版
hdu1042 N!(大数)
Performance optimization | CPU power management from the perspective of ping delay
Oracle存储修改以前的历史记录,怎么查找?
Lecture 4: Database Definition Language of DDL Type of SQL Statements
计算机网络面试常问知识
FastDFS distributed file system
3D角色建模师和3D角色动画师哪个更有前景?哪个更适合小白入门?