views:

286

answers:

1

What MFC control should I use and how should I use it to display constantly changing text (like progress text) on a dialog?

For example, should I use the static text control? But can you change it programmatically?

+2  A: 

Yes, you can change the contents of a static control programmatically. Change the ID to something other than IDC_STATIC, then you can assign a member variable to it. You can set the text with your_var.SetWindowText().

Edit: how many changes are you making, and how fast? I did a quick test program with a timer (set to a duration of 0) that formats and writes a new string to the control when the time fires, so it's updating constantly. Here's what it looks like after running for a while:

Test program

And here's what Task Manager shows:

Task Manager

The spike a the right is (at least mostly) from taking the screen shot of the test program saving it, and so on. As soon as I quit doing things like that, CPU usage went back to do noise level (with the occasional blip). I left the program running -- a half hour or so later, it's still doing fine, with no noticeable CPU usage (in fast according to Task Manager, it hasn't used even one second of CPU time yet).

Jerry Coffin
I've done that, and for some reason it seems to use up CPU after many frequent changes
Vanwaril
Can you change the font and color of a static text control programmatically?
Chetan
@Chetan:Yes. To change the font, call its `SetFont()` member. To change the background color, return a brush in response to `WM_CTLCOLOR` or `WM_CTLCOLORSTATIC`. To set the text color, call `SetTextColor()` for the DC you receive when handling `WM_CTLCOLOR`.
Jerry Coffin