I want to change caption (text) of a label in the execution time depending on user input. If user presses a button, my program will execute some stuff and write the output into a label. But I have a problem about this.
First, there’s no label in my environment. At least in toolbox. I know, adding from toolbox is not the only way, but I’m a bit scared to touch the old source code and mess things up.
I found a static text element, but I guess because of its a “static” element, I can’t see it in resource.h. So, if I use a function like GetDlgItem(IDC_STATIC);, it doesn’t work. Because there’s no IDC_STATIC in my resource.h.
This was the second one.
And, I used SetDlgItemText(IDC_STATIC, "text");, too. However, because of my resource.h doesn’t know what IDC_STATIC is, I get errors.
Is there a label class/element that is not in toolbox? I guess my IDC_STATIC is not in my resource.h because of its static behavior. Or, is there any other way to update the text of a label/static text?
Thanks for your help.
You want to use a static control, but give it some identifier other than IDC_STATIC. Then you’ll be able to use
GetDlgItemText,SetDlgItemText, etc., with that identifier. Alternatively, you could/can use an EDIT control set to read-only, which is pretty much equivalent to a static control1.1Even more than many realize — for example, to change the background color of a normal edit control, you respond to
WM_CTLCOLOREDIT. To change the background color of a static control or read-only edit control, you respond toWM_CTLCOLORSTATIC.