Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 307
ivan.ukr Avatar asked Jul 09 '26 05:07

ivan.ukr


1 Answers

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().

like image 107
Jonathan Potter Avatar answered Jul 11 '26 20:07

Jonathan Potter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!