1、让对话框从CdialogResize类继承过来:
class CMainDlg : public CDialogImpl
public CDoubleBufferImpl
public CDialogResize
2、添加消息路由
BEGIN_MSG_MAP(CMainDlg)
CHAIN_MSG_MAP(CDialogResize
CHAIN_MSG_MAP(CDoubleBufferImpl
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
class CMainDlg : public CDialogImpl
public CDoubleBufferImpl
public CDialogResize
{
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;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章