本文介绍了更改 SetDlgItemText 颜色的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,我使用 SetDlgItemText 来显示文本,但我想将文本颜色从黑色更改为灰色,使其在屏幕上显示为灰色.我尝试了 settextcolor,知道这是一个很长的镜头,但没有奏效.

Question is pretty straight forward, I'm using SetDlgItemText to display text, but I want to change the text color from black to grey so it appears grey on the screen. I tried settextcolor, knowing that was a long shot and it didn't work.

这是我创建框的代码

SetDlgItemText(hDlg, IDC_EDIT2, password_string);

推荐答案

您没有提到控件是静态控件还是编辑控件.

在对话框过程中使用如下代码;对于编辑控件:在 case WM_CTLCOLOR 下,对于静态控件在 case WM_CTLCOLORSTATIC:

You don't mention whether the control is a static or an edit control.

Use code like the following in your dialog proc;For Edit controls: under case WM_CTLCOLOR and for Static controls under case WM_CTLCOLORSTATIC:

case WM_CTLCOLOREDIT:
    if (::GetDlgCtrlID((HWND) lParam) == IDC_MY_CONTROL)
    {   HBRUSH hbr = (HBRUSH) DefWindowProc(hDlg, iMessage, wParam, lParam);
        SetTextColor((HDC) wParam, RGB(192, 192, 192));
        return (BOOL) hbr;
    }
    return FALSE;

这篇关于更改 SetDlgItemText 颜色的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:18