zoukankan      html  css  js  c++  java
  • WTL设置对话框背影色

    MainDlg.h

    // MainDlg.h : interface of the CMainDlg class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #pragma once
    
    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 OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    	LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    };
    
    MainDlg.cpp

    // MainDlg.cpp : implementation of the CMainDlg class
    //
    /////////////////////////////////////////////////////////////////////////////
    
    #include "stdafx.h"
    #include "resource.h"
    
    #include "MainDlg.h"
    #include <atlimage.h>
    #include <time.h>
    
    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);
    
    	return TRUE;
    }
    
    LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    {
    	EndDialog(wID);
    	return 0;
    }
    
    LRESULT CMainDlg::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
    	srand((unsigned)time(NULL));
    	CPaintDC dc(this->m_hWnd);
    	CBrush brush;
    	CRect rect;
    	GetClientRect(&rect);
    	InvalidateRect(&rect, FALSE);
    	brush.CreateSolidBrush(RGB(rand() % 255, rand() % 255, rand() % 255));
    	dc.FillRect(&rect, brush);
    	return TRUE;
    }
    无限次刷新客户区,实现重绘。

    class CPaintDC : public CDC
    {
    public:
    // Data members
    	HWND m_hWnd;
    	PAINTSTRUCT m_ps;
    
    // Constructor/destructor
    	CPaintDC(HWND hWnd)
    	{
    		ATLASSERT(::IsWindow(hWnd));
    		m_hWnd = hWnd;
    		m_hDC = ::BeginPaint(hWnd, &m_ps);
    	}
    
    	~CPaintDC()
    	{
    		ATLASSERT(m_hDC != NULL);
    		ATLASSERT(::IsWindow(m_hWnd));
    		::EndPaint(m_hWnd, &m_ps);
    		Detach();
    	}
    };
    可见,CPaintDC封装了只能在WM_PAINT消息下处理的BeginPaint、EndPaint函数。

    case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps);
    EndPaint(hwnd, &ps);

    return 0;



    Keep it simple!
    作者:N3verL4nd
    知识共享,欢迎转载。
  • 相关阅读:
    兼容性测试中如何切换和管理多个JDK版本
    Win10的分辨率问题
    sql和access中截取字符串的区别
    ArcGIS制图之Sub Points点抽稀
    Office版本问题0x80029C4A
    ArcGIS制图之Maplex自动点抽稀
    ArcGIS制图之Subset工具点抽稀
    .NET破解之100%营销QQ辅助软件【更新】
    Office2016体验
    Log4net中的调错
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616370.html
Copyright © 2011-2022 走看看