• WTL改变对话框大小


    1、让对话框从CdialogResize类继承过来:

    class CMainDlg : public CDialogImpl<CMainDlg>,
    public CDoubleBufferImpl<CMainDlg>,
    public CDialogResize<CMainDlg>

    2、添加消息路由

    BEGIN_MSG_MAP(CMainDlg)
    CHAIN_MSG_MAP(CDialogResize<CMainDlg>)
    CHAIN_MSG_MAP(CDoubleBufferImpl<CMainDlg>)
    MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
    END_MSG_MAP()

    3、添加消息映射

    BEGIN_DLGRESIZE_MAP(CMainDlg)
    DLGRESIZE_CONTROL(IDC_STATIC_INPUT,  DLSZ_SIZE_X)
    DLGRESIZE_CONTROL(IDC_STATIC_SEARCH, DLSZ_SIZE_X | DLSZ_SIZE_Y)
    END_DLGRESIZE_MAP()


    4、在OnInitDialog()中调用DlgResize_Init();


    当对话框存在GroupBox的话,需要将GroupBox设置为透明背影

    Transparent:true

    测试代码:

    MainDlg.h

    // MainDlg.h : interface of the CMainDlg class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #pragma once
    #include <gdiplus.h>
    
    class CMainDlg : public CDialogImpl<CMainDlg>,
    	public CDoubleBufferImpl<CMainDlg>,
    	public CDialogResize<CMainDlg>
    {
    public:
    	enum { IDD = IDD_MAINDLG };
    
    	BEGIN_MSG_MAP(CMainDlg)
    		CHAIN_MSG_MAP(CDialogResize<CMainDlg>)
    		CHAIN_MSG_MAP(CDoubleBufferImpl<CMainDlg>)
    		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
    	END_MSG_MAP()
    
    	BEGIN_DLGRESIZE_MAP(CMainDlg)
    		DLGRESIZE_CONTROL(IDC_STATIC_INPUT,  DLSZ_SIZE_X)
    		DLGRESIZE_CONTROL(IDC_STATIC_SEARCH, DLSZ_SIZE_X | DLSZ_SIZE_Y)
    	END_DLGRESIZE_MAP()
    
    // Handler prototypes (uncomment arguments if needed):
    //	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    //	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    //	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
    
    	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    	void DoPaint(CDCHandle dc);
    private:
    	Gdiplus::GdiplusStartupInput gGdiInput;
    	ULONG token;
    };
    
    MainDlg.cpp

    // MainDlg.cpp : implementation of the CMainDlg class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #include "stdafx.h"
    #include "resource.h"
    
    #include "MainDlg.h"
    #pragma comment(lib, "GdiPlus.lib")
    
    LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
    	// center the dialog on the screen
    	CenterWindow();
    
    	// set icons
    	HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
    	SetIcon(hIcon, TRUE);
    	HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
    	SetIcon(hIconSmall, FALSE);
    
    	GdiplusStartup(&token, &gGdiInput, NULL);
    
    	DlgResize_Init();
    	return TRUE;
    }
    
    void CMainDlg::DoPaint(CDCHandle dc)
    {
    	RECT rect;
    	GetClientRect(&rect);
    	
    	Gdiplus::Graphics g(dc);
    	Gdiplus::Image im(_T("res/green.jpg"));
    	g.DrawImage(&im, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
    }
    
    LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    {
    	Gdiplus::GdiplusShutdown(token);
    	EndDialog(wID);
    	return 0;
    }
    



    Keep it simple!
    作者:N3verL4nd
    知识共享,欢迎转载。
  • 相关阅读:
    thinkphp3.2生成二维码
    php实现图片下载
    yii2.0 Activeform表单部分组件使用方法
    Yii2美化confirm
    Yii2学习笔记之场景
    tp5页面输出时,搜索后跳转下一页的处理
    php页面输出时,js设置input框的选中值
    mac中使用rz,sz上传文件
    golang的命令行程序开发
    Sring MVC基于Java Config方式配置Mybatis, 无XML
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616316.html
Copyright © 2020-2023  润新知