Advertisement

Updating Fields On A Dialog Box

Started by July 16, 2001 05:48 AM
0 comments, last by WizzardUK 23 years, 5 months ago
Hey ppl, Can anyone help? I''m not a newbie (I have been using C++ at Uni for some time) but I don''t know much more than the basics. I am trying to get into Visual C++ (using MFC''s). Does anyone know how to update a text field on a dialog box with a char* field. I know I can use the SetDlgItemText() function to update fields in a window, but this doesn''t seem to work (or I can''t get it to work) with a dialog box. It will compile fine, but the field is left blank. If anyone can help, I would appreciate it greatly. Cheers Wizzard
First, you must attach a member variable to the edit box. To do this go into Class Wizard, select the Member Variables tab, select the ID of the edit box, and click Add Variable. Enter a name, select the type, etc.

Now, if you want the variable to have an initial value that is displayed when the dialog box is created go to the dialog classes constructor. Find your variable and enter your initial value.

OK, so you now have a variable and it has a value. I''m not sure if this value will be displayed right away or not. If not what you need to do is add the line UpdateData(FALSE); to the dialog''s OnInitDialog() function.

That ought to do it. Whenever you want to change the text in the program change the variable''s value and call UpdateData(FALSE); If you want to set the value of the variable to be the text in the edit box call UpdatData(TRUE); Whenever either changes you must call UpdateData() to keep them synchronized. Hope that answers your question.

This topic is closed to new replies.

Advertisement