请问CEdit类如何在只读模式下,设置背景颜色?

解决方案 »

  1.   

    继承一个它的类
    OnCtlColor()
      

  2.   

    // MyEdit.cpp : implementation file
    //#include "stdafx.h"
    #include "dlg.h"
    #include "MyEdit.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMyEditCMyEdit::CMyEdit()
    {
       m_bluecolor=RGB(0,0,255); // blue
       m_bluebrush.CreateSolidBrush(m_bluecolor); // blue background
    }CMyEdit::~CMyEdit()
    {
    }
    BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
    //{{AFX_MSG_MAP(CMyEdit)
    ON_WM_CTLCOLOR_REFLECT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyEdit message handlersHBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
    {
      HBRUSH hbr;  pDC->SetBkColor(m_bluecolor); // change the background color

      hbr = (HBRUSH) m_bluebrush; //  apply the brush
    return hbr;
    }-----------------------------------------
    #if !defined(AFX_MYEDIT_H__26502F97_38CA_47F6_B986_B58C15E14BEE__INCLUDED_)
    #define AFX_MYEDIT_H__26502F97_38CA_47F6_B986_B58C15E14BEE__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // MyEdit.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CMyEdit windowclass CMyEdit : public CEdit
    {
    // Construction
    public:
    CMyEdit();// Attributes// Operations
    public:// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyEdit)
    //}}AFX_VIRTUAL// Implementation
    public:
    virtual ~CMyEdit(); // Generated message map functions
    protected:
    //{{AFX_MSG(CMyEdit)
    afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
    //}}AFX_MSG DECLARE_MESSAGE_MAP()
    private:
         CBrush m_bluebrush;
         COLORREF m_bluecolor;
    };///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYEDIT_H__26502F97_38CA_47F6_B986_B58C15E14BEE__INCLUDED_)
      

  3.   

    也可以在对话框类中处理WM_CTLCOLOR。
      

  4.   

    同上,
    www.vckbase.com第14期中有源码
      

  5.   

    http://www.vckbase.com/vckbase/第十四期 的WINDOWS标准界面元素中第一个文章,内涵源码