• 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
    知识共享,欢迎转载。
  • 相关阅读:
    Quartz使用及注意事项
    .Net下性能调优浅析
    .Net下Redis使用注意事项
    WCF服务开发与调用的完整示例
    超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
    C# DES
    webService访问加密-Soapheader
    WebMethod 属性
    互联网 免费的WebService接口
    利用XPath解析带有xmlns的XML文件
  • 原文地址:https://www.cnblogs.com/lgh1992314/p/6616369.html
Copyright © 2020-2023  润新知