zoukankan      html  css  js  c++  java
  • 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
    知识共享,欢迎转载。
  • 相关阅读:
    start tag, end tag issues in IE7, particularly in xslt transformation
    用SandCastle为注释生成chm文档
    Firebug
    架构的重点
    Linux Shell常用技巧(十) 管道组合
    Linux JDK升级
    Linux Shell常用技巧(十二) Shell编程
    Packet Tracer 5.0实验(一) 交换机的基本配置与管理
    Linux Shell常用技巧(六) sort uniq tar split
    Linux Shell常用技巧(二) grep
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616368.html
Copyright © 2011-2022 走看看