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

老子叫甜甜 提交于 2019-12-13 05:36:56

问题


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


回答1:


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);



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/9196048/visual-studio-c-how-to-display-a-dynamic-message-i-e-string-in-my-about-bo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!