更改编辑控件中文本的背景 [英] Changing background of text in edit control

查看:31
本文介绍了更改编辑控件中文本的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否更改编辑控件区域中文本的背景以保持静态?

Can you change the background of text in area of edit control that would stay static?

推荐答案

在编辑控件的父级中,处理WM_CTLCOLORSTATIC 消息,该消息的 wParam 是 Edit 控件即将使用的 HDC,对于大多数 CTLCOLOR 消息,如果您在此 DC 中设置文本和背景颜色,则控件将使用您设置的颜色.

In the parent of the edit control, handle the WM_CTLCOLORSTATIC message, the wParam of this message is the HDC that the Edit control is about to draw with, for most CTLCOLOR messages, if you set text and background colors into this DC, the control will use the colors you set.

您也可以返回一个 HBRUSH 并且控制器将使用它来进行任何画笔绘制,但是许多控件不会使用太多画笔,因此对于某些控件来说效果有限CTLCOLOR 消息.最好的办法是返回 DC 笔刷,并将 DC 笔刷颜色设置为与 DC 的 BkColor 匹配.

You can also return an HBRUSH and the contol will use that for any brush painting that it wil do, but many controls don't use brushes much, so that will have limited effect for some CTLCOLOR messages. Your best bet here is to return the DC brush, and set the DC Brush color to match the BkColor of the DC.

 LRESULT lRet = 0; // return value for our WindowProc.
 COLORREF crBk = RGB(255,0,0); // use RED for Background.

 ... 

 case WM_CTLCOLORSTATIC:
    {
    HDC hdc = (HDC)wParam;
    HWND hwnd = (HWND)lParam; 

    // if multiple edits and only one should be colored, use
    // the control id to tell them apart.
    //
    if (GetDlgCtrlId(hwnd) == IDC_EDIT_RECOLOR)
       {
       SetBkColor(hdc, crBk); // Set to red
       SetDCBrushColor(hdc, crBk);
       lRet = (LRESULT) GetStockObject(DC_BRUSH); // return a DC brush.
       }
    else
       {
       lRet = DefWindowProc(hwnd, uMsg, wParam, lParam);
       }
    }
    break;

这篇关于更改编辑控件中文本的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆