• WTL对话框添加背景图片


    WTL91_5321_Final + VS2013 + WIN7

    // MainDlg.h : interface of the CMainDlg class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #pragma once
    #include <GdiPlus.h>
    #include <atlimage.h>
    extern Gdiplus::GdiplusStartupInput gGdiInput;
    
    class CMainDlg : public CDialogImpl<CMainDlg>
    {
    public:
    	enum { IDD = IDD_MAINDLG };
    
    	BEGIN_MSG_MAP(CMainDlg)
    		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    		MESSAGE_HANDLER(WM_PAINT, OnPaint)
    		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
    	END_MSG_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 OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    private:
    	CImage bg;
    };
    
    1、对话框头文件(MainDlg.h)添加:

    #include <GdiPlus.h>
    extern Gdiplus::GdiplusStartupInput gGdiInput;
    2、添加消息映射

    MESSAGE_HANDLER(WM_PAINT, OnPaint)

    LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

    3、对话框源文件(MainDlg.cpp)添加:

    #pragma comment(lib, "GdiPlus.lib")
    Gdiplus::GdiplusStartupInput gGdiInput;
    ULONG token = 0;

    OnInitDialog函数内进行Gdiplus初始化

    GdiplusStartup(&token, &gGdiInput, NULL);

    重载OnPaint消息响应函数:

    LRESULT CMainDlg::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
    	CPaintDC dc(m_hWnd);
    	RECT rect;
    	GetClientRect(&rect);
    	HDC hDC = dc.m_hDC;
    	Gdiplus::Graphics g(hDC);
    	Gdiplus::Image im(_T("res/green.jpg"));
    	g.DrawImage(&im, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
    	return TRUE;
    }
    关闭:

    Gdiplus::GdiplusShutdown(token);

    // MainDlg.cpp : implementation of the CMainDlg class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #include "stdafx.h"
    #include "resource.h"
    
    #include "MainDlg.h"
    #include "table.h"
    #pragma comment(lib, "GdiPlus.lib")
    Gdiplus::GdiplusStartupInput gGdiInput;
    ULONG token = 0;
    
    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);
    
    
    	//CTable table;
    
    	return TRUE;
    }
    
    LRESULT CMainDlg::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
    	CPaintDC dc(m_hWnd);
    	RECT rect;
    	GetClientRect(&rect);
    	HDC hDC = dc.m_hDC;
    	Gdiplus::Graphics g(hDC);
    	Gdiplus::Image im(_T("res/green.jpg"));
    	g.DrawImage(&im, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
    	return TRUE;
    }
    
    LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    {
    	bg.Destroy();
    	Gdiplus::GdiplusShutdown(token);
    	EndDialog(wID);
    	return 0;
    }
    


    参考于:

    http://blog.csdn.net/faithzzf/article/details/51897140

    Keep it simple!
    作者:N3verL4nd
    知识共享,欢迎转载。
  • 相关阅读:
    Python基础学习参考(四):条件与循环
    Python基础学习参考(三):内置函数
    Python基础学习参考(二):基本语法
    2011的最后一篇博文 写给我自己也写给你们
    前端开发面试题
    常用js操作:
    两个嵌套for循环执行顺序
    在寻找学习js的途中,又发现了好的东西!
    arcgis api for js初学
    解决为什么arcgis api for js的first map里不显示arcgis地图
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616368.html
Copyright © 2020-2023  润新知