当前位置:网站首页>Dialog manager in the fourth chapter: the dialog message loop
Dialog manager in the fourth chapter: the dialog message loop
2022-08-03 03:52:00 【Topological Mel-Long Development Road】
The dialog message loop is actually not complicated. Its core implementation code is the following lines of code:
while (However, let's start from the beginning.The story happens when DialogBoxIndirectParam is called. You should remember that we explained before that the system will convert all calls to DialogBoxXX into calls to DialogBoxIndirectParam. The code is as follows:
INT_PTR WINAPI DialogBoxIndirectParam(HINSTANCE hinst,LPCDLGTEMPLATE lpTemplate, HWND hwndParent,DLGPROC lpDlgProc, LPARAM lParam){/** App hack! Some people pass GetDesktopWindow()* as the owner instead of NULL. Fix them so the* desktop doesn't get disabled!*/if (hwndParent == GetDesktopWindow())hwndParent = NULL;Yes, we did an App Hack in the code.In the previous article, we discussed the issue of passing GetDesktopWindow() as the parent window.A lot of developers made this mistake and we had to build this App Hack into the core OS code.If we don't do this, hundreds of upper layer applications will need to be changed.
Since only top-level windows can be the window owner, we have to start from hwndParent (possibly a child window) and work our way up the window hierarchy until we find a top-level window.
if (hwndParent)hwndParent = GetAncestor(hwndParent, GA_ROOT);After completing the second App Hack, we started to create our dialog:
HWND hdlg = CreateDialogIndirectParam(hinst,lpTemplate, hwndParent, lpDlgProc,lParam);Note: As before, I'll ignore error checking and various dialog boxes, as it just distracts from the point of this entry.
Because modal dialogs disable their parent window, implement it here:
BOOL fWasEnabled = EnableWindow(hwndParent, FALSE);Then we enter the dialog modal message loop:
MSG msg;while (According to the convention of window exit messages, we redelive any exit message we might receive so that it can be seen by the next outer modal loop.
if (msg.message == WM_QUIT) {PostQuitMessage((int)msg.wParam);}(Astute readers may have noticed look, there is an uninitialized variable error in the code above: if EndDialog is called during WM_INITDIALOG processing, msg.message is never set. For illustration purposes, I decidedIgnore this error.)
At this point, our dialog has done its job, and we need to clean it up.Remember to enable the owner before destroying the owned dialog.
if (fWasEnabled)EnableWindow(hwndParent, TRUE);DestroyWindow(hdlg);Finally, return the result:
return ;} Congratulations, you are now a dialog expert.Tomorrow, we'll see how to make the most of the expertise learned today.
Exercise: Find a way to sneak through the App Hack about the parent window in the two layers of code above to end up with a dialog whose owner is the desktop, and explain the dire consequences of this situation.
Summary
Okay, dialog expert, you see it: there is nothing mysterious under the code, there is cause and effect.
This world is still materialistic.
Last
Raymond Chen's "The Old New Thing" is one of my favorite blogs. It contains a lot of small knowledge about Windows, which is really helpful for the majority of Windows platform developers.
This article is from: "The dialog manager, part 4: The dialog loop"

边栏推荐
猜你喜欢

js Fetch返回数据res.json()报错问题

HCIP第十八天

浅谈用KUSTO查询语言(KQL)在Azure Synapse Analytics(Azure SQL DW)审计某DB账号的操作记录

【leetcode热题Hot100】——任务调度器

PyTorch安装——安装PyTorch前在conda搭建虚拟环境的报错

【笔记】混淆矩阵和ROC曲线

【STM32】入门(三):按键使用-GPIO端口输出控制

中原银行实时风控体系建设实践

Pro * C Jin Cang database migration guide (4) KingbaseES Pro * C migration guide)

Kotlin multiplication, how do I multiply smaller and smaller?
随机推荐
【翻译】开发与生产中的Kubernetes修复成本对比
智能健身动作识别:PP-TinyPose打造AI虚拟健身教练!
金仓数据库 MySQL 至 KingbaseES 迁移最佳实践(3. MySQL 数据库移植实战)
Domino服务器SSL证书安装指南
LeetCode算法日记:面试题 03.04. 化栈为队
【无标题】2022-7-24
compose 位移视图
vscode hide activity bar
成都高新南区 高新西区 东部新区 多边形范围点位 AOI 高德
log4j设置日志的时区
path development介绍
SMP 需要考虑的事情
数字3d虚拟交互展厅顺应时代发展需求和趋势
工业边缘计算研究现状与展望
PyTorch installation - error when building a virtual environment in conda before installing PyTorch
MediaRecorder录制屏幕时在部分机型上报错prepare failed:-22
【剑指offer】——16.数值的整数次方
种草一个让程序员男友编程时,记住一辈子的 IDEA 神仙插件!
Senior ClickHouse -
金仓数据库 Pro*C 迁移指南( 4. KingbaseES 的 Pro*C 迁移指南)