简体   繁体   中英

Visual Studio C++ how to display a dynamic message (i.e., string) in my About box?

Should be trivial . . . when editing via the VS resource editor.... the tools/objects list only shows 'static text' and the create an event handler wizard has all fields and [next] button dimmed (disabled).

I have a lovely About box -- it all works -- but instead of static text fields to display --

I want/need to display several lines (strings) of current runtime status info.....

I just do know Visual Studio well enough (I'm using 2008). . .

If any one has a simple example -- that really is all I need.

Thanks in advance.

best regards, Kevin Waite

If you put a static text box in your dialog you can set its text to anything you want at runtime. First you need to get the window handle of the text box:

HWND hwndText = GetDlgItem(hwndDialog, IDC_MYTEXT);

Then you can set the new text into it:

SetWindowText(hwndText, L"Hi mom, this is my first text box!");

Static text isn't meant to change, so Windows doesn't always do the right thing when you change it. You need to tell it to erase and repaint so that the new text is properly displayed.

InvalidateRect(hwndText, NULL, true);

How about adding an empty static text, and just setting its Text property?

I just made an empty Windows Forms application in Visual Studio C++ Express, and dragged a "Label" control onto the form. In the forms Load function, the text can be set like this:

this->label1->Text = "Hello World";

The same method can be used if you want larger texts. Just use a multiline TextBox instead.

If you want to display multiple lines of text, you can use the EditBox control and set the multiline property to True.

To pass the data to the about dialog, you will need to have to pass those strings to the dialog when the dialog is created (before the call to DoModal); and have the string added to the editbox in the aboutbox OnInitDialog.

If you need the text to be updated live while the about dialog is open you will probably have to add a thread that will fetch the strings from somewhere and the UI will be updated with those new strings.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM