0

As I am working in Win32, I want to display a message using SetDlgItemText. The message should vary its color depending on success or failure (say for example green for success, red for failure).

The code for the function:
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; }

In the above code "Please enter a key" and "Please enter all the user information" should be in red color indicating failure. We set default as green for ID_RESULT. Is it possible to change color using SetTextColor function in the IF condition itself or else give some other options

1 Answers1

2

If you use Edit Control, please refer 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.

If you use Static Control, please refer 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.

For detailed code operation, see this.

Strive Sun
  • 5,988
  • 1
  • 9
  • 26
  • What is iMessage in DefWindowProc(hDlg, iMessage, wParam, lParam) ? – Mohanasudharsan K Feb 25 '20 at 06:08
  • @MohanasudharsanK It represents window messages, iMessage is just a parameter name. See [DefWindowProc](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-defwindowproca) – Strive Sun Feb 25 '20 at 06:16
  • @See [Designing a Window Procedure](https://learn.microsoft.com/en-us/windows/win32/winmsg/using-window-procedures#designing-a-window-procedure), you can modify the name of the parameter(such as: iMessage or uMsg...) – Strive Sun Feb 25 '20 at 06:21
  • Sun - It works fine using WM_CTLCOLORSTATIC. Thank you. – Mohanasudharsan K Feb 25 '20 at 11:08