How to create a text field within a dialog box
-
Hi, I need to create a text field within a dialog box, where i want some data to be printed out (i.e., to show) . How do I start ? Thanks, Deepak Samuel
-
Hi, I need to create a text field within a dialog box, where i want some data to be printed out (i.e., to show) . How do I start ? Thanks, Deepak Samuel
I assume you already have a dialog working. Got to the resource editor and add a static text control. Its ID is going to be IDC_STATIC change that to your own ID. Like IDC_MYTEXT. What you put as the text of the static control is going to be the text that is initially displayed. Now, in one of your dialog message handler, wherever you want to change the text on the dialog, put the following: CStatic* pText = (CStatic*) GetDlgItem(IDC_MYTEXT); //get a pointer to the control pText->SetWindowText(“Hello World”); //set the text When the message handler is called the text is going to change to Hello World. This works with an edit box too. Make an Edit box on your resource template with ID IDC_MYEDIT. The following code will display the text. CEdit* pEdit = (CEdit*) this->GetDlgItem(IDC_MYEDIT); pEdit->SetWindowText("Hello World"); I hope this helps. Lorenz Prem Microsoft Corporation
-
I assume you already have a dialog working. Got to the resource editor and add a static text control. Its ID is going to be IDC_STATIC change that to your own ID. Like IDC_MYTEXT. What you put as the text of the static control is going to be the text that is initially displayed. Now, in one of your dialog message handler, wherever you want to change the text on the dialog, put the following: CStatic* pText = (CStatic*) GetDlgItem(IDC_MYTEXT); //get a pointer to the control pText->SetWindowText(“Hello World”); //set the text When the message handler is called the text is going to change to Hello World. This works with an edit box too. Make an Edit box on your resource template with ID IDC_MYEDIT. The following code will display the text. CEdit* pEdit = (CEdit*) this->GetDlgItem(IDC_MYEDIT); pEdit->SetWindowText("Hello World"); I hope this helps. Lorenz Prem Microsoft Corporation
You might want to consider using an EDIT control instead of a STATIC, and then set the ReadOnly property on it. The advantage is that users will be able to copy & scroll the data in the control. If you don't plan on displaying all that much data, then maybe the STATIC is the right way to go.
-
I assume you already have a dialog working. Got to the resource editor and add a static text control. Its ID is going to be IDC_STATIC change that to your own ID. Like IDC_MYTEXT. What you put as the text of the static control is going to be the text that is initially displayed. Now, in one of your dialog message handler, wherever you want to change the text on the dialog, put the following: CStatic* pText = (CStatic*) GetDlgItem(IDC_MYTEXT); //get a pointer to the control pText->SetWindowText(“Hello World”); //set the text When the message handler is called the text is going to change to Hello World. This works with an edit box too. Make an Edit box on your resource template with ID IDC_MYEDIT. The following code will display the text. CEdit* pEdit = (CEdit*) this->GetDlgItem(IDC_MYEDIT); pEdit->SetWindowText("Hello World"); I hope this helps. Lorenz Prem Microsoft Corporation
Jeez, even the guys at MS don't know about
SetDlgItemText
. I don't know about you, but I find a one-liner much more readable:SetDlgItemText( IDC_MYEDIT, _T( "Hello World" ) );
Also, there's no need to cast to a CEdit or CStatic pointer if you're just going to be calling a method implemented on CWnd. -
Jeez, even the guys at MS don't know about
SetDlgItemText
. I don't know about you, but I find a one-liner much more readable:SetDlgItemText( IDC_MYEDIT, _T( "Hello World" ) );
Also, there's no need to cast to a CEdit or CStatic pointer if you're just going to be calling a method implemented on CWnd.I agree that your solution is much more elegant and readable, but getting a pointer to the control is also a vital step in many other not so basic scenarios. I figure I better answer the question the way it is most useful, not necessarily in the shortest way. That includes the cast, which might be necessary for other things besides setting the text. Lorenz Prem Microsoft Corporation
-
I agree that your solution is much more elegant and readable, but getting a pointer to the control is also a vital step in many other not so basic scenarios. I figure I better answer the question the way it is most useful, not necessarily in the shortest way. That includes the cast, which might be necessary for other things besides setting the text. Lorenz Prem Microsoft Corporation