`

CDialogResize

    博客分类:
  • VC++
 
阅读更多

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 whether CDialogResize adds a size box to the bottom-right corner of the dialog. Pass true to add the size box, or false to not add it.
  • bUseMinTrackSize: This parameter controls whether CDialogResize restricts the minimum size of the dialog. If you pass true, the dialog is not allowed to be sized smaller than its initial size (as stored in the resource file). Pass false 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.

 [Dlg control IDs - 17K]

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:

 [Main dialog - 28K] /

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:

 [Bigger dialog - 61K]

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();
}
<!-- Article Ends --><!-- Main Page Contents End -->

 

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

 

分享到:
评论

相关推荐

    WTL CDialogResize扩展

    扩展WTL CDialogResize模板以支持持久对话框大小

    使用CDialogResize调整大小的属性表/向导

    使属性表/向导可调整大小,而无需进行大量修改。

    一个字体按钮类(WTL)VC源代码

    一个使用WTL的字体按钮类。 关键字:WTL,CDialogResize,CFontButton,字体按钮类

    node-v0.11.6-sunos-x86.tar.gz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    node-v0.10.46-linux-x86.tar.gz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    计二 王顺.zip

    计二 王顺.zip

    qbittorrent_4.6.4_lt20_qt6_x64_setup.exe

    qbittorrent_4.6.4_lt20_qt6_x64_setup

    课设毕设基于SSM的美食推荐管理系统-LW+PPT+源码可运行.zip

    课设毕设基于SSM的美食推荐管理系统--LW+PPT+源码可运行

    node-v0.11.13-x64.msi

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    基于yolov5+SlowFast+pyqt5的人体动作识别项目源码+使用说明(毕业设计).zip

    基于yolov5+SlowFast+pyqt5的人体动作识别项目源码+使用说明(毕业设计).zip该项目是个人毕设项目源码,评审分达到97分,都经过严格调试,确保可以运行!放心下载使用。该项目资源主要针对计算机相关专业的学生或从业者下载使用,也可作为期末课程设计、课程大作业、毕业设计等。 1.项目代码均经过功能验证ok,确保稳定可靠运行。欢迎下载体验!下载完使用问题请私信沟通。 2.主要针对各个计算机相关专业,包括计算机科学、信息安全、数据科学与大数据技术、人工智能、通信、物联网等领域的在校学生、专业教师、企业员工。 3.项目具有丰富的拓展空间,不仅可作为入门进阶,也可直接作为毕设、课程设计、大作业、初期项目立项演示等用途。 基于yolov5+SlowFast+pyqt5的人体动作识别项目源码+使用说明(毕业设计).zip该项目是个人毕设项目源码,评审分达到97分,都经过严格调试,确保可以运行!放心下载使用。该项目资源主要针对计算机相关专业的学生或从业者下载使用,也可作为期末课程设计、课程大作业、毕业设计等。基于yolov5+SlowFast+pyqt5的人体动作识别项目源码

    【毕业设计】基于yolov9 ncnn模型部署到android源码+模型+项目说明.zip

    高分毕业设计源码 基于YOLO的毕业选题设计的程序源码,适用与计算机与软件工程毕业设计选题

    node-v0.12.17-linux-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    基于Qt的简单学生管理系统

    简单的学生管理系统,主要使用的Qt框架,数据库使用的Mysql,包含增删改查,排序等功能

    nodejs-ia32-0.10.13.tgz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    wx078上门维修系统-springboot+vue+uniapp-小程序.zip(可运行源码+sql文件+文档)

    根据本系统的基本设计思路,本系统在设计方面前台采用了java技术等进行基本的页面设计,后台数据库采用MySQL。本系统的实现为上门维修系统的运行打下了基础,为上门维修提供良好的条件。 最后我们通过需求分析、测试调整,与上门维修的实际需求相结合,设计实现了基于微信小程序的上门维修系统。 本课题要求实现优质的上门维修系统,就一定要包含有前台页面和后端数据库、服务器相联系,从而实现系统的功能运转。系统分为前台用户模块、维修员模块和管理员模块三部分;(1)、用户进入系统可以实现首页,广告信息,新闻资讯,我的,在我的页面可以对维修信息,维修记录,评价信息,我的收藏管理进行管理。(2)、维修员进入系统可以实现首页,广告信息,新闻资讯,我的,在我的页面可以对维修信息,维修记录,评价信息等进行管理。(3)、管理员主要包括系统首页,个人中心,用户管理,维修员管理,维修信息管理,维修记录管理,评价信息管理,广告信息管理,系统管理等有关功能进行管理。 关键词:上门维修;java;MySQL数据库

    node-v0.1.94.tar.gz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    Optimizer-16.4.exe

    Optimizer-16.4

    毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip

    毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip个人经导师指导并认可通过的高分毕业设计项目,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者。也可作为课程设计、期末大作业,项目都经过严格调试,确保可以运行! 毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学习安全聚合系统python源码.zip毕设项目基于同态加密的联邦学

    【课程设计】基于python实现三维重建算法SFM源码.zip

    【课程设计】基于python实现三维重建算法SFM源码.zip

    kouzhao-mainunity游戏

    unity游戏

Global site tag (gtag.js) - Google Analytics