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

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

问题描述

您可以改变文本的背景的编辑控制区,将保持静态的?

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

推荐答案

在编辑控件的父,处理的 WM_CTLCOLORSTATIC 消息,此消息的wParam为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的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天全站免登陆