• How to change the background color of an Edit Box


     

    How to change the background color of an Edit Box

    http://www.codeproject.com/cpp/cppfaq10dec04-23jan05.asp

    You can change the background color of an edit control in a dialog by handling the WM_CTLCOLOR message in the dialog

    class MyDialog : public CDialog {

    //...

        COLORREF _BkgColor;

        HBRUSH   _BkgBrush;

    };

    BOOL MyDialog::OnInitDialog()

    {

    //...

        _BkgColor = RGB(0,255,0);

        _BkgBrush = ::CreateSolidBrush(_BkgColor);

    }

    HBRUSH MyDialog::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor )

    {

        hbr = CDialog::OnCtlColor(pDC,pWnd,nCtlColor);

        if (pWnd()->GetDlgCtrlId() == IDC_MY_EDIT_CONTROL) {

            pDC->SetBkColor(_BkgColor);

            hbr = _BkgBrush;

           }

        return hbr;

    }

    In the OnInitDialog() handler for the dialog, we initialize the background color value and create a brush in that color. The WM_CTLCOLOR handler is called OnCtlColor. The edit control for which we want to change the color has the resource ID IDC_MY_EDIT_CONTROL. We set the text background to our background color using SetBkColor(), and the overall background for the control by returning the brush we created.

  • 相关阅读:
    Regexp:教程
    Regexp:目录
    笔记-C#:C# 方法、属性杂项-01
    Regexp:正则表达式应用——实例应用
    正则表达式:百科
    Regexp:template
    AngularJS:参考手册
    命令目录
    java实现连续数的公倍数
    java实现连续数的公倍数
  • 原文地址:https://www.cnblogs.com/cy163/p/531840.html
Copyright © 2020-2023  润新知