• 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
    知识共享,欢迎转载。
  • 相关阅读:
    hdu 1532 网络最大流
    POJ 2407 素数筛
    hdoj 4081 次小生成树
    hdoj 1251 统计难题
    hdoj 1176 免费馅饼
    ouc oj 1066 青蛙过河
    POJ 2533 Longest Ordered Subsequence(单调递增子序列)
    POJ 1159 Palindrome(回文字符串)
    POJ-1458 Common Subsequence (最长公共子序列)
    POJ-2593 Max Sequence(不连续的最大子段和)
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616368.html
Copyright © 2020-2023  润新知