zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    THINKPHP3.2视频教程
    PHPCMS 学习
    PHPCMS 后台学习
    phpcms 模板学习
    二叉树的创建与遍历(链式存储)
    MySQL基础~~增、删、改、简单查
    队列的基本操作(链队列)
    MySQL基础~~表结构操作
    行编辑程序
    循环链表的基本操作
  • 原文地址:https://www.cnblogs.com/cy163/p/531840.html
Copyright © 2011-2022 走看看