ivan.ukr
ivan.ukr

Reputation: 3582

Set StaticText control text using pure Windows API, no MFC

I am attempting to write a very small graphical program for Windows in the Visual C++ using pure Windows API. Program consists of the one dialog with couple buttons and static text control. Dialog is initializaed from resource. What I need to do is when dialog initialized, static text is filled with some value, that is dynamicallt computed. I am stuck at his point, because I completely don't know how to change static text value on the dialog dynamically. Please advise. I assume that must be call to SetWindowText(), but the question is - how do I determine hWnd for the particular static text on the dialog?

Upvotes: 3

Views: 4217

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37202

In your resource script the control would have a particular ID (e.g. IDC_STATIC). The simplest way to change its text in that case is:

SetDlgItemText(hwndDlg, IDC_STATIC, L"the new text");

Alternatively, you can use GetDlgItem() to get the handle to the control using its ID and then call SetWindowText().

Upvotes: 7

Related Questions