- 浏览: 61450 次
- 性别:
- 来自: 株洲
-
文章分类
最新评论
-
yuvista:
礼顶膜拜,我心中的大神!一个在生活中迷失的程序员向您致敬!
一个程序员的奋斗历程(再发经典,这是我见过最牛的程序员了
Introduction
Recently I've been reading up on WTL, and I came across a rather interesting class that I hadn't seen mentioned anywhere, CDialogResize
. Given the large number of MFC implementations of resizable dialogs, it's great that WTL provides its own, so you only have to learn one class and one way of specifying what gets resized. In this article, I will outline WTL's resizing support and provide a sample program to illustrate some of the features. You should already be familiar with WTL and how to install it. If you need help with this, there are articles on those subjects in the WTL section.
Using CDialogResize
The basics
As with many other WTL features, you begin by adding CDialogResize
to the inheritance list of your dialog class. So, if you make a dialog-based app with the WTL AppWizard, you would add the line listed here in red:
class CMainDlg : public CAxDialogImpl<CMainDlg>, public CDialogResize<CMainDlg>
CDialogResize
is declared in atlframe.h, so add that header to your includes if it isn't there already.
The next step is to initialize the CDialogResize
code in your dialog's OnInitDialog
handler:
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // Init the CDialogResize code DlgResize_Init(); ... }
DlgResize_Init()
has a few optional parameters, which I'll cover later.
Next, add an entry in the dialog's message map that passes sizing messages to CDialogResize
:
BEGIN_MSG_MAP(CMainDlg) MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) ... CHAIN_MSG_MAP(CDialogResize<CMainDlg>) END_MSG_MAP()
Finally, add a new map to the dialog class that lists which controls in the dialog will be resized:
class CMainDlg : public CAxDialogImpl<CMainDlg>, public CDialogResize<CMainDlg> { ... public: BEGIN_DLGRESIZE_MAP(CMainDlg) END_DLGRESIZE_MAP() ... };
I'll describe how to fill in this map in the "Setting up the resize map" section.
Initializing CDialogResize
CDialogResize
is initialized by calling to DlgResize_Init()
. Its prototype is:
void CDialogResize::DlgResize_Init ( bool bAddGripper = true, bool bUseMinTrackSize = true, DWORD dwForceStyle = WS_THICKFRAME | WS_CLIPCHILDREN );
The parameters are:
-
bAddGripper
: This controls whetherCDialogResize
adds a size box to the bottom-right corner of the dialog. Passtrue
to add the size box, orfalse
to not add it. -
bUseMinTrackSize
: This parameter controls whetherCDialogResize
restricts the minimum size of the dialog. If you passtrue
, the dialog is not allowed to be sized smaller than its initial size (as stored in the resource file). Passfalse
if you don't want to restrict the dialog's minimum size. -
dwForceStyle
: Specifies window styles to apply to the dialog. The default value is usually sufficient.
Setting up the resize map
The dialog resize map tells CDialogResize
which controls to move or size. An entry looks like this:
DLGRESIZE_CONTROL(ControlID, Flags)
ControlID
is the ID of the dialog control. The possible flags and their meanings are:
-
DLSZ_SIZE_X
: Resize the width of the control as the dialog resizes horizontally. -
DLSZ_SIZE_Y
: Resize the height of the control as the dialog resizes vertically. -
DLSZ_MOVE_X
: Move the control horizontally as the dialog resizes horizontally. -
DLSZ_MOVE_Y
: Move the control vertically as the dialog resizes vertically. -
DLSZ_REPAINT
: Invalidate the control after every move/resize so it repaints every time.
Note that you cannot move and size a control in the same dimension. If you specify, say DLSZ_MOVE_X
and DLSZ_SIZE_X
together, the size flag is ignored.
You can also group controls together so that they move and size proportionally to each other. I will cover this subject later.
Sample Project
The sample project included with this article is a simple dialog-based app that functions as a browser (using the WebBrowser ActiveX control). The control IDs are listed below; you should refer back to this diagram later when I discuss moving and resizing these controls.
The controls will move and size according to these rules:
- The Location edit box will resize horizontally.
- The Go, Exit, and About buttons will move horizontally.
- The Back, Forward, Stop, and Refresh buttons will resize horizontally in a group.
- The browser control will resize horizontally and vertically
The browser's OnInitDialog()
function initializes CDialogResize
like this:
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { // Init the CDialogResize code DlgResize_Init(); ... }
This uses the default parameters to DlgResize_Init()
, which results in a size box being added. Also, the dialog cannot be sized smaller than its initial size. Here's what the dialog looks like on startup:
Here is the resize map, which lists the moving and sizing behavior for the controls. Note the new macros - BEGIN_DLGRESIZE_GROUP()
and END_DLGRESIZE_GROUP()
- that put the four browser control buttons into a resizing group.
BEGIN_DLGRESIZE_MAP(CMainDlg) // Location edit box DLGRESIZE_CONTROL(IDC_URL, DLSZ_SIZE_X) // Go, Exit, About buttons DLGRESIZE_CONTROL(IDC_GO, DLSZ_MOVE_X) DLGRESIZE_CONTROL(IDC_EXIT, DLSZ_MOVE_X) DLGRESIZE_CONTROL(ID_APP_ABOUT, DLSZ_MOVE_X) // IE control buttons BEGIN_DLGRESIZE_GROUP() DLGRESIZE_CONTROL(IDC_BACK, DLSZ_SIZE_X) DLGRESIZE_CONTROL(IDC_FORWARD, DLSZ_SIZE_X) DLGRESIZE_CONTROL(IDC_STOP, DLSZ_SIZE_X) DLGRESIZE_CONTROL(IDC_REFRESH, DLSZ_SIZE_X) END_DLGRESIZE_GROUP() // WebBrowser control DLGRESIZE_CONTROL(IDC_BROWSER, DLSZ_SIZE_X|DLSZ_SIZE_Y) END_DLGRESIZE_MAP()
Here is the dialog after being resized:
Notice how the edit box is wider, and the browser control is wider and taller. The behavior of the four grouped buttons is a bit tough to put into words, and the WTL code offers little guidance since there are few comments. But the basic idea is: imagine a bounding rectangle that surrounds all four buttons. That rectangle resizes like any other control, and all the buttons are sized proportionally so they remain within the bounding rectangle. If the buttons were to be moved, instead of resized, they would be positioned to always be evenly spaced apart. Note that all the controls in a group should have the same DLSZ_*
flags to produce meaningful behavior.
Bugs and Problems with CDialogResize
So far, I've only seen two problems. One is that there seems to be an off-by-one bug somewhere, because the first time you resize the dialog, some of the controls shift the wrong direction by one pixel. The other, more serious problem, is a bug in the WTL AppWizard that is exposed when you add CDialogResize
as a base class of your dialog. The AppWizard-generated code that displays the dialog looks like this:
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { // ... CMainDlg dlgMain; int nRet = dlgMain.DoModal(); _Module.Term(); ::CoUninitialize(); return nRet; }
The trouble with that is the CMainDlg
destructor is called after _Module.Term()
. This causes a crash in a release build if it is built with the _ATL_MIN_CRT
symbol defined. The solution is to put the CMainDlg
object in an enclosing block:
int nRet;
{
CMainDlg dlgMain;
nRet = dlgMain.DoModal();
}
License
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
发表评论
-
CListCtrl和CImageList显示缩略图,图片自动排列。
2011-04-06 14:30 8405的CListCtrl风格设置为ICON风格 CImag ... -
有用的vc获取当前目录的代码
2011-03-11 16:02 1122//获取当前目录CString GetModuleDir(){ ... -
Visual C++多媒体设计及图形、图像处理
2011-03-07 13:14 921在VC下显示JPEG、GIF格式图像的一种简便方法一、 引言 ... -
vc制作异形窗口的方法
2011-02-26 15:01 1048http://wenku.baidu.com/view/d4a ... -
add a status bar to an MFC dialog
2011-02-08 11:48 1672we can get the method from the ... -
QQ找茬外挂 开源
2011-01-12 11:31 937http://hi.baidu.com/blue236146_ ... -
LPTSTR详解
2011-01-07 10:02 1156LPTSTR 与char*等价,表示普通字符/字符串变量 ... -
Unicode下MFC获取命令行参数,执行脚本制作
2011-01-06 15:07 2446在MFC程序中,可以用以下几种方法来获取命令行参数。 ... -
INT_PTR介绍
2011-01-06 09:07 2738不知道是从哪个版本的SDK开始,微软引入了一个新的类型——IN ... -
VC++多线程编程
2011-01-05 12:48 1357多线程编程之一——问题提出 一、问题的提出编写一个耗时的单线 ... -
VC++文件操作
2010-12-30 17:40 921文件属性相关 1.判断文件是否存在 利用CFile类和CF ... -
vc++ 如何使radio button ,checkbox初始为已选状态?
2010-12-29 11:28 1712CheckDlgButton(IDC_CHECK1, BS ... -
vc++ 开源异步socket通信项目
2010-12-21 17:28 1118http://www.codeproject.com/KB/I ... -
smtp小记录,慢慢记录
2010-12-17 08:46 670我的smtp小研究,正在开发一个vc++的邮件客户端,goog ...
相关推荐
**WTL CDialogResize扩展**是Windows Template Library (WTL)的一个增强功能,它使得对话框在用户调整大小时能够保持其元素的相对位置和比例,从而提供更友好的用户体验。在传统的Windows应用程序中,对话框通常在...
`CDialogResize`类提供了一种便捷的方法来实现对话框和属性表的大小调整功能,使得用户可以根据需要自由地改变窗口尺寸。这个技术尤其适用于希望在不大量修改代码的情况下实现窗口自适应大小的应用程序。 标题...
当对话框的尺寸改变时,CDialogResize可以自动调整其子控件的位置和大小,使得界面布局始终保持美观和合理。这对于创建响应用户界面大小调整的应用程序非常有用。 3. **CFontButton类**: 这个源代码的核心是...
基于万能逼近原理的自适应模糊控制算法在多自由度AUV运动控制中的应用与抗干扰补偿Simulink仿真研究,自适应模糊控制算法的万能逼近原理与多自由度AUV运动控制的抗干扰补偿技术——基于Simulink的仿真研究,万能逼近原理自适应模糊控制算法的多自由度AUV运动控制抗干扰补偿simulink仿真 ,核心关键词:万能逼近原理; 自适应模糊控制算法; 多自由度AUV运动控制; 抗干扰补偿; Simulink仿真。,基于万能逼近的模糊控制算法多自由度AUV抗干扰补偿Simulink仿真
deepseek最新资讯、配置方法、使用技巧,持续更新中
deepseek最新资讯、配置方法、使用技巧,持续更新中
结合扩展卡尔曼滤波与滑模观测器的策略:优化电角度估计,反电势波形逼近完美正弦波,结合扩展卡尔曼滤波与滑模观测器的反电势波形优化:正弦波形展现近乎完美精度,电角度估算与实际应用差异微小,扩展卡尔曼滤波与滑模观测器的结合,反电势波形近乎完美的正弦波形,观测器估算转子电角度与实际电角度相差0.3弧度左右,转速跟随效果较好。 ,核心关键词:扩展卡尔曼滤波; 滑模观测器; 反电势波形; 转子电角度估算; 转速跟随效果。,卡尔曼滑模观测器:优化正弦波转子角度与转速估算
毕业设计_基于springboot+vue的**学生公寓管理系统**【源码+sql+可运行】【**50217**】.zip 全部代码均可运行,亲测可用,尽我所能,为你服务; 1.代码压缩包内容 代码:springboo后端代码+vue前端页面代码; 脚本:数据库SQL脚本 效果图:运行结果请看资源详情效果图 2.环境准备: - JDK1.8+ - maven3.6+ - nodejs14+ - mysql5.6+ - redis 3.技术栈 - 后台:springboot+mybatisPlus+Shiro - 前台:vue+iview+Vuex+Axios - 开发工具: idea、navicate 4.功能列表 - 系统设置:用户管理、角色管理、资源管理、系统日志 - **业务管理:业务管理:公寓信息、房间信息、入住记录、学生信息** 3.运行步骤: 步骤一:修改数据库连接信息(ip、port修改) 步骤二:找到启动类xxxApplication启动 4.若不会,可私信博主!!!
1、文件内容:xorg-x11-server-source-1.20.4-29.el7_9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/xorg-x11-server-source-1.20.4-29.el7_9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
1、文件内容:yum-plugin-ps-1.1.31-54.el7_8.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/yum-plugin-ps-1.1.31-54.el7_8.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、更多资源/技术支持:公众号禅静编程坊
基于模型预测控制(MPC)的无人船与无人车编队一致性协同控制研究(附原文献),基于模型预测控制(MPC)的无人船与无人车编队一致性协同控制研究(附原文献),无人船编队 无人车编队 MPC 模型预测控制 多智能体协同控制 一致性 MATLAB 无人车 USV 带原文献 ,无人船编队; 无人车编队; MPC 模型预测控制; 多智能体协同控制; 一致性; MATLAB; USV; 原文献,无人系统协同控制:MPC模型预测控制下的多智能体编队与一致性研究(原文献支撑)
4套中级通信工程师综合真题及答案(2019,2020,2021,2023),适用于需要考中级通信工程师的人群
deepseek最新资讯,配置方法,使用技巧,持续更新中
基于matlab的锁相环PLL相位噪声拟合仿真代码集合:多个版本建模与仿真,高质量的锁相环PLL仿真代码集合:Matlab与Simulink建模研究,[1]锁相环 PLL 几个版本的matlab相位噪声拟合仿真代码,质量杠杠的,都是好东西 [2]锁相环matlab建模稳定性仿真,好几个版本 [3]锁相环2.4G小数分频 simulink建模仿真 ,PLL; Matlab相位噪声拟合仿真; Matlab建模稳定性仿真; 锁相环2.4G小数分频Simulink建模仿真,MATLAB仿真系列:锁相环PLL及分频器建模仿真
exceptionLogs.zip
基于光伏微网的经济性与并网负荷波动率双目标优化调度策略:蓄电池与V2G协同管理策略仿真研究,MATLAB下光储充微网结合电动汽车V2G的多目标协同调度策略研究:经济性与并网负荷波动性的对比分析,MATLAB代码:考虑V2G的光储充一体化微网多目标优化调度策略 关键词:光储充微网 电电汽车V2G 多目标优化 蓄电池优化 调度 参考文档:《光伏微网下考虑V2G补偿蓄电池容量的双目标优化调度策略》,已经投稿EI会议,中文说明文档可联系我咨询 仿真平台:MATLAB 平台 优势:代码注释详实,适合参考学习,相关成果已经采用,程序非常精品,请仔细辨识 主要内容:过建立光伏微网中以经济性和并网负荷波动率为双目标的蓄电池和V2G的协同调度模型。 采用粒子群算法,对电网、微网调度中心和电动汽车用户三方在无、无序、转移和调度V2G电动汽车负荷四种运行模式下的经济和安全影响进行对比。 最后,根据算例分析,求解四种模式下两级负荷曲线及经济收益表。 对比分析得出,引入V2G可以替代部分容量的蓄电池,使光伏微网在负荷峰谷平抑、三方经济和安全等方面进一步优化。 求解采用的是PSO算法(粒子群算法),求解效果极
javascript 动态网页设计期末大作业(自己手写的,高分期末作业),含有代码注释,新手也可看懂,个人手打98分项目,导师非常认可的高分项目,毕业设计、期末大作业和课程设计高分必看,下载下来,简单部署,就可以使用。该项目可以直接作为毕设、期末大作业使用,代码都在里面,系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值,项目都经过严格调试,确保可以运行! javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期末大作业(自己手写的,高分期末作业)javascript 动态网页设计期
混合智能体系统编队控制:分布式优化与15异构混合阶的挑战,异构混合阶智能体系统编队控制的分布式优化策略研究,15异构混合阶多智能体系统编队控制的分布式优化(无参考文献) ,核心关键词:15异构混合阶; 多智能体系统; 编队控制; 分布式优化; 无参考文献。,15混合阶多智能体系统编队分布式优化控制
javascript 动态网页设计期末大作业(自己手写的,很适合期末作业),含有代码注释,新手也可看懂,个人手打98分项目,导师非常认可的高分项目,毕业设计、期末大作业和课程设计高分必看,下载下来,简单部署,就可以使用。该项目可以直接作为毕设、期末大作业使用,代码都在里面,系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值,项目都经过严格调试,确保可以运行! javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascript 动态网页设计期末大作业(自己手写的,很适合期末作业)javascrip
X光安检OPIXray数据集已经转换为VOC格式,可直接转换为为YOLO