当前位置:网站首页>Dialog manager Chapter 3: create controls
Dialog manager Chapter 3: create controls
2022-07-27 15:07:00 【Topomeyer - long development road】
Compared with the previous article on creating frame windows , Creating controls is much easier , Believe it or not .
Each control defined in the dialog template , Its corresponding sub window will be created . The size and position of the control are in the template with DLU Described in units , therefore , Of course , We need to convert them to pixels , The code is as follows :
int x = XDLU2Pix(ItemTemplate.x);
int y = YDLU2Pix(ItemTemplate.y);
int cx = XDLU2Pix(ItemTemplate.cx);
int cy = YDLU2Pix(ItemTemplate.cy);
The control class name and title also come from the template . There are also some optional extra bytes pExtra No one uses , But it remains in the template definition for historical reasons . Once this information is collected , It's time to make ” Doughnut ” 了 .
HWND hwndChild = CreateWindowEx(
ItemTemplate.dwExStyle | WS_EX_NOPARENTNOTIFY,
pszClass, pwzCaption, ItemTemplate.dwStyle,
x, y, cx, cy, hdlg, ItemTemplate.dwId,
hinst, pExtra);
Please note that , For dialog controls ,WS_EX_NOPARENTNOTIFY Styles are enabled by default .
The next part often makes people stumble . “ When I try to create my dialog , It failed , I don't know why? .” This may be because a control on the dialog cannot be created , Usually because you forget to register the window class for this control . ( for example , You forgot to call InitCommonControlsEx Function or forget LoadLibrary Appropriate version RichEdit Control .)
if (!hwndChild) {
DestroyWindow(hdlg);
return NULL;
}
DS_NOFAILCREATE The style prohibits the above failure check .
however , If you do create a control , You need to initialize it .
SetWindowContextHelpId(hwndChild, ItemTemplate.dwHelpID);
SetWindowFont(hwndChild, hf, FALSE);
After repeating the above steps for each control in the template , You now have a dialog containing all the child controls . Tell the dialog process that it can initialize its child windows , If we delay building the framework WS_VISIBLE position , Is displayed ( Now ready ) Dialog box , And return the dialog box to our caller , The dialog box is now ready .
// The default focus is the first item that is a valid tab-stop.
HWND hwndDefaultFocus = GetNextDlgTabItem(hdlg, NULL, FALSE);
if (SendMessage(hdlg, WM_INITDIALOG, hwndDefaultFocus, lParam)) {
SetDialogFocus(hwndDefaultFocus);
}
if (fWasVisible) ShowWindow(hdlg);
return hdlg;
}
About SetDialogFocus, We talked about that before .
thus , You should understand how the dialog box is created .
( actually , The reality is much more complicated , Because I skipped all the application compatibility skills ! for example , There is a program that depends on detailed settings and WS_BORDER The lack of style determines whether the control is a combo box or a list box . I guess GetClassName The workload of functions is too large ?)
I hope this will help you better understand how conversation templates work .
summary
Descriptive language , It is a very friendly way of communication between program developers and operating systems .
like COM In the era of IDL( Interface description language ).
Last
Raymond Chen Of 《The Old New Thing》 It's one of my favorite blogs , There's a lot about Windows Little knowledge , For the vast Windows For platform developers , It's really helpful .
This article is from :《The dialog manager, part 3: Creating the controls》

边栏推荐
猜你喜欢

仅做两项修改,苹果就让StyleGANv2获得了3D生成能力

STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示

LeetCode 783. 二叉搜索树节点最小距离 树/easy

对话框管理器第三章:创建控件

How to do well in enterprise system vulnerability assessment

Kubernetes 节点磁盘故障排查

Visual system design example (Halcon WinForm) -10. PLC communication

Research on multi label patent classification based on pre training model

关于 CMS 垃圾回收器,你真的懂了吗?

What if win11 wallpaper turns black? The solution of win11 wallpaper blackening
随机推荐
@What happens when bean and @component are used on the same class?
Confirm the time accuracy of the power supply setting voltage through the i/o function of vn1630/vn7640
How to do well in enterprise system vulnerability assessment
FPGA timing constraint sharing 04_ Output delay constraint
Nokia's patent business was hit for the first time, and Chinese enterprises are not so easy to knead
Hdu3117 Fibonacci numbers [mathematics]
Detailed explanation of Telnet remote login AAA mode [Huawei ENSP]
MySQL save data prompt: out of range value for column error
网络设备硬核技术内幕 路由器篇 (10) CISCO ASR9900拆解 (四)
UnityUI方面处理(归纳与积累)
微信小程序实现音乐搜索页面
网络设备硬核技术内幕 路由器篇 3 贾宝玉梦游太虚幻境 (中)
NEFU118 n! How many zeros are there after [basic theorem of arithmetic]
LeetCode 781. 森林中的兔子 哈希表/数学问题 medium
Nefu117 number of prime numbers [prime number theorem]
User question understanding and answer content organization for epidemic disease Science Popularization
通过VN1630/VN7640的I/O功能来确认电源设置电压的时间精确度
Getting started with DirectX
cap理论和base理论
OBS 进阶之 DXGI 采集屏幕流程,并如何修改为自己的光标