Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ranthalion

Changing text in a dialog box?

This topic is 5233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a static text control in a dialog box and when the user presses the ok button, I want to change the text that is displayed. I''m using a dialog box as my main window for the application. How would I change the text displayed? In VB it was something as simple as Dialog.Text1.caption="New text", but obviously, that doesn''t work with C++. I''m using MSVC++ 6.0.

Share this post


Link to post
Share on other sites
Advertisement
That's what I'm having trouble with now.. I don't know how to get the handle of the control. It was created with the resource editor. I have the hWnd to the dialog box, but how do I get the HWND to the static text box?

[edited by - Ranthalion on February 26, 2004 10:17:23 PM]

Share this post


Link to post
Share on other sites
Alternatively you can use SetDlgItemText() and use the HWND of the dialog and the ID of the control.


Thanks Salsa!Colin Jeanne | Invader''s Realm
"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud

Share this post


Link to post
Share on other sites
I found and tried GetDlgItem and the way InvaderX just told me about, but neither of them change the text. I don''t receive any errors and the Control identifier is correct, but it just doesn''t show any change when I press the button. Do I have to repaint the window or invalidate it or something before the change takes effect? Here is a sample of my code:


LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{


switch(Msg)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
switch(wParam)
{
case IDNEXT:
SetDlgItemText(hWndDlg,IDFINISH,"now with new text");
return TRUE;

case FILE_EXIT:
case WM_DESTROY:
PostQuitMessage(0);
EndDialog(hWndDlg,0);
return 0;
}
break;
}

return FALSE;
}

Share this post


Link to post
Share on other sites
Are you sure IDFINISH is what you want? Is that the ID of the static text control? And by the way, can you change the text of a static text control? Try using an ''edit control''. If you don''t want the user to be able to type text in it you can disable it.

Share this post


Link to post
Share on other sites
I''m sure that IDFINISH is the correct ID, changing it to an edit control fixed my problem. Thanks for the help. I have another question then, how do the words change in programs like installers where you just click next to and new text replaces the old?

Share this post


Link to post
Share on other sites
I guess I was wrong. You can change the text of a static text control:

quote:
Visual Studio documentation:
An application can change the text in a text static control at any time by using the SetWindowText function or the WM_SETTEXT message.


I recommend you take a look at the Platform SDK docs (User Interface Services).

Share this post


Link to post
Share on other sites
Thanks. I changed it back to a static text control and it works now. No noticeable changes made though, so I don''t really understand why it works now and not before.
I''ve been looking through the MSDN, but it is large and difficult to find the information I need. I usually use google and go to the MSDN results... Again, thanks for all the help.

Share this post


Link to post
Share on other sites
It took me a while to really get used to the MSDN docs. Now i can''t live without them. Use the Help\Contents view and filter by Visual C++. You''ll have all the docs about C++, Platform SDK, MFC, etc, available.

One thing that really helps a lot is the ''Help\Sync Contents'' command. When you are viewing some help page that command will expand the MSDN''s docs contents all the way to that page. That way you can easily find related stuff.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!