如何在 win32 中使用 SetTextColor 更改文本 SetDlgItemText 的颜色?

How to change color of text SetDlgItemText using SetTextColor in win32?

由于我在 Win32 工作,我想使用 SetDlgItemText 显示消息。该消息应根据成功或失败而改变其颜色(例如,绿色表示成功,红色表示失败)。

函数代码:
if { //if user does not enter a key SetDlgItemText(hDlg, ID_RESULT, L"Please enter a key"); return false; } else { SetDlgItemText(hDlg, ID_RESULT, L"Please enter all the user information"); return false; }

在上面的代码中,"Please enter a key"和"Please enter all the user information"应该是红色的,表示失败。我们将 ID_RESULT 的默认设置为绿色。是否可以在 IF 条件本身中使用 SetTextColor 函数更改颜色,或者提供一些其他选项

如果使用编辑控件,请参考WM_CTLCOLOREDIT

An edit control that is not read-only or disabled sends the WM_CTLCOLOREDIT message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control.

如果使用静态控制,请参考WM_CTLCOLORSTATIC

A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text foreground and background colors of the static control.

详细代码操作见