0

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.

EDIT: Here is the code I have that creates the box

SetDlgItemText(hDlg, IDC_EDIT2, password_string);
WakkaDroid
  • 138
  • 12
  • And SetDialogItemText is part of... what? Could you at least write the name of the library or framework you're using? – José Tomás Tocino Aug 07 '15 at 23:32
  • @JoséTomásTocino it's part of winAPI – WakkaDroid Aug 07 '15 at 23:40
  • 1
    @WakkaDroid - no,it isn't. Perhaps you actually mean `SetDlgItemText`? – enhzflep Aug 07 '15 at 23:41
  • 3
    `SetDialogItemText` changes the .. text. It changes the string. It doesn't change the color. To change the text color of a control requires different approaches for different types of control. Sometimes it's not possible at all. It's impossible to help further without you telling us what type of control you're talking about. – Jonathan Potter Aug 07 '15 at 23:44
  • 1
    *What's the proper way of changing the color of SetDlgItemText?* `SetDlgItemText` is a function and functions don't have color. It pays to be more studied and precise in use of language. – David Heffernan Aug 08 '15 at 07:09

2 Answers2

2

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_CTLCOLOREDIT: 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;
Edward Clements
  • 5,040
  • 2
  • 21
  • 27
1

Cannot do that with Stock dialogs.

Option #1 - use WM_CTLCOLORSTATIC

Option #2 - USE RTF by swapping/switching to a Rich Edit Control

abRao
  • 2,787
  • 1
  • 25
  • 37