- 浏览: 62090 次
- 性别:
- 来自: 株洲
-
文章分类
最新评论
-
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 8427的CListCtrl风格设置为ICON风格 CImag ... -
有用的vc获取当前目录的代码
2011-03-11 16:02 1141//获取当前目录CString GetModuleDir(){ ... -
Visual C++多媒体设计及图形、图像处理
2011-03-07 13:14 931在VC下显示JPEG、GIF格式图像的一种简便方法一、 引言 ... -
vc制作异形窗口的方法
2011-02-26 15:01 1060http://wenku.baidu.com/view/d4a ... -
add a status bar to an MFC dialog
2011-02-08 11:48 1681we can get the method from the ... -
QQ找茬外挂 开源
2011-01-12 11:31 944http://hi.baidu.com/blue236146_ ... -
LPTSTR详解
2011-01-07 10:02 1169LPTSTR 与char*等价,表示普通字符/字符串变量 ... -
Unicode下MFC获取命令行参数,执行脚本制作
2011-01-06 15:07 2450在MFC程序中,可以用以下几种方法来获取命令行参数。 ... -
INT_PTR介绍
2011-01-06 09:07 2750不知道是从哪个版本的SDK开始,微软引入了一个新的类型——IN ... -
VC++多线程编程
2011-01-05 12:48 1366多线程编程之一——问题提出 一、问题的提出编写一个耗时的单线 ... -
VC++文件操作
2010-12-30 17:40 933文件属性相关 1.判断文件是否存在 利用CFile类和CF ... -
vc++ 如何使radio button ,checkbox初始为已选状态?
2010-12-29 11:28 1727CheckDlgButton(IDC_CHECK1, BS ... -
vc++ 开源异步socket通信项目
2010-12-21 17:28 1132http://www.codeproject.com/KB/I ... -
smtp小记录,慢慢记录
2010-12-17 08:46 681我的smtp小研究,正在开发一个vc++的邮件客户端,goog ...
相关推荐
**WTL CDialogResize扩展**是Windows Template Library (WTL)的一个增强功能,它使得对话框在用户调整大小时能够保持其元素的相对位置和比例,从而提供更友好的用户体验。在传统的Windows应用程序中,对话框通常在...
`CDialogResize`类提供了一种便捷的方法来实现对话框和属性表的大小调整功能,使得用户可以根据需要自由地改变窗口尺寸。这个技术尤其适用于希望在不大量修改代码的情况下实现窗口自适应大小的应用程序。 标题...
当对话框的尺寸改变时,CDialogResize可以自动调整其子控件的位置和大小,使得界面布局始终保持美观和合理。这对于创建响应用户界面大小调整的应用程序非常有用。 3. **CFontButton类**: 这个源代码的核心是...
内容概要:本文详细介绍了如何利用Matlab构建、优化和应用决策分类树。首先,讲解了数据准备阶段,将数据与程序分离,确保灵活性。接着,通过具体实例展示了如何使用Matlab内置函数如fitctree快速构建决策树模型,并通过可视化工具直观呈现决策树结构。针对可能出现的过拟合问题,提出了基于成本复杂度的剪枝方法,以提高模型的泛化能力。此外,还分享了一些实用技巧,如处理连续特征、保存模型、并行计算等,帮助用户更好地理解和应用决策树。 适合人群:具有一定编程基础的数据分析师、机器学习爱好者及科研工作者。 使用场景及目标:适用于需要进行数据分类任务的场景,特别是当需要解释性强的模型时。主要目标是教会读者如何在Matlab环境中高效地构建和优化决策分类树,从而应用于实际项目中。 其他说明:文中不仅提供了完整的代码示例,还强调了代码模块化的重要性,便于后续维护和扩展。同时,对于初学者来说,建议从简单的鸢尾花数据集开始练习,逐步掌握决策树的各项技能。
《营销调研》第7章-探索性调研数据采集.pptx
Assignment1_search_final(1).ipynb
美团优惠券小程序带举牌小人带菜谱+流量主模式,挺多外卖小程序的,但是都没有搭建教程 搭建: 1、下载源码,去微信公众平台注册自己的账号 2、解压到桌面 3、打开微信开发者工具添加小程序-把解压的源码添加进去-appid改成自己小程序的 4、在pages/index/index.js文件搜流量主广告改成自己的广告ID 5、到微信公众平台登陆自己的小程序-开发管理-开发设置-服务器域名修改成
《计算机录入技术》第十八章-常用外文输入法.pptx
基于Andorid的跨屏拖动应用设计实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
《网站建设与维护》项目4-在线购物商城用户管理功能.pptx
区块链_房屋转租系统_去中心化存储_数据防篡改_智能合约_S_1744435730
《计算机应用基础实训指导》实训五-Word-2010的文字编辑操作.pptx
《移动通信(第4版)》第5章-组网技术.ppt
ABB机器人基础.pdf
《综合布线施工技术》第9章-综合布线实训指导.ppt
很不错的一套站群系统源码,后台配置采集节点,输入目标站地址即可全自动智能转换自动全站采集!支持 https、支持 POST 获取、支持搜索、支持 cookie、支持代理、支持破解防盗链、支持破解防采集 全自动分析,内外链接自动转换、图片地址、css、js,自动分析 CSS 内的图片使得页面风格不丢失: 广告标签,方便在规则里直接替换广告代码 支持自定义标签,标签可自定义内容、自由截取、内容正则截取。可以放在模板里,也可以在规则里替换 支持自定义模板,可使用标签 diy 个性模板,真正做到内容上移花接木 调试模式,可观察采集性能,便于发现和解决各种错误 多条采集规则一键切换,支持导入导出 内置强大替换和过滤功能,标签过滤、站内外过滤、字符串替换、等等 IP 屏蔽功能,屏蔽想要屏蔽 IP 地址让它无法访问 ****高级功能*****· url 过滤功能,可过滤屏蔽不采集指定链接· 伪原创,近义词替换有利于 seo· 伪静态,url 伪静态化,有利于 seo· 自动缓存自动更新,可设置缓存时间达到自动更新,css 缓存· 支持演示有阿三源码简繁体互转· 代理 IP、伪造 IP、随机 IP、伪造 user-agent、伪造 referer 来路、自定义 cookie,以便应对防采集措施· url 地址加密转换,个性化 url,让你的 url 地址与众不同· 关键词内链功能· 还有更多功能等你发现…… 程序使用非常简单,仅需在后台输入一个域名即可建站,不限子域名,站群利器,无授权,无绑定限制,使用后台功能可对页面进行自定义修改,在程序后台开启生 成功能,只要访问页面就会生成一个本地文件。当用户再次访问的时候就直接访问网站本地的页面,所以目标站点无法访问了也没关系,我们的站点依然可以访问, 支持伪静态、伪原创、生成静态文件、自定义替换、广告管理、友情链接管理、自动下载 CSS 内的图。
【自然语言处理】文本分类方法综述:从基础模型到深度学习的情感分析系统设计
基于Andorid的下拉浏览应用设计实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
内容概要:本文详细介绍了一个原创的P2插电式混合动力系统Simulink模型,该模型基于逻辑门限值控制策略,涵盖了多个关键模块如工况输入、驾驶员模型、发动机模型、电机模型、制动能量回收模型、转矩分配模型、运行模式切换模型、档位切换模型以及纵向动力学模型。模型支持多种标准工况(WLTC、UDDS、EUDC、NEDC)和自定义工况,并展示了丰富的仿真结果,包括发动机和电机转矩变化、工作模式切换、档位变化、电池SOC变化、燃油消耗量、速度跟随和最大爬坡度等。此外,文章还深入探讨了逻辑门限值控制策略的具体实现及其效果,提供了详细的代码示例和技术细节。 适合人群:汽车工程专业学生、研究人员、混动汽车开发者及爱好者。 使用场景及目标:①用于教学和科研,帮助理解和掌握P2混动系统的原理和控制策略;②作为开发工具,辅助设计和优化混动汽车控制系统;③提供仿真平台,评估不同工况下的混动系统性能。 其他说明:文中不仅介绍了模型的整体架构和各模块的功能,还分享了许多实用的调试技巧和优化方法,使读者能够更好地理解和应用该模型。
内容概要:本文详细介绍了基于ADMM(交替方向乘子法)算法在电力系统分布式调度中的应用,特别是并行(Jacobi)和串行(Gauss-Seidel)两种不同更新模式的实现。文中通过MATLAB代码展示了这两种模式的具体实现方法,并比较了它们的优劣。并行模式适用于多核计算环境,能够充分利用硬件资源,尽管迭代次数较多,但总体计算时间较短;串行模式则由于“接力式”更新机制,通常收敛更快,但在计算资源有限的情况下可能会形成瓶颈。此外,文章还讨论了惩罚系数rho的自适应调整策略以及在电-气耦合系统优化中的应用实例。 适合人群:从事电力系统优化、分布式计算研究的专业人士,尤其是有一定MATLAB编程基础的研究人员和技术人员。 使用场景及目标:①理解和实现ADMM算法在电力系统分布式调度中的应用;②评估并行和串行模式在不同应用场景下的性能表现;③掌握惩罚系数rho的自适应调整技巧,提高算法收敛速度和稳定性。 其他说明:文章提供了详细的MATLAB代码示例,帮助读者更好地理解和实践ADMM算法。同时,强调了在实际工程应用中需要注意的关键技术和优化策略。