简体   繁体   中英

What's the proper way of changing the color of SetDlgItemText?

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);

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM