Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a default value for "Edit control box" in a Dialog that is added to MFC Doc/Frame project

Tags:

visual-c++

mfc

I added a extra Dialog (TestDialog) in a MFC doc/frame project (Single doc, MFC, VC++2010 project) That dialog has a "EDIT Control" (IDC_EDIT1, m_EditBox1 etc) box. After starting the MFC program from the DOC/frame Menu I selected the testdialog which then popup or start.

But Whenver I start that Testdialog the EDIT Control box appear as empty and I have to type a starting value (say 100) so that I can press a button (inside testdialog) that runs a program which accept 100 as input.

How and where I can add a starting value say 100 to this Edit control so that when testdialog will open the EDIT control box already will have that default vale ( i,e 100).

TestDialog.cpp file shows

CTestDialog::CTestDialog(CWnd* pParent /*=NULL*/)
: CDialogEx(CTestDialog::IDD, pParent)
, testdlg(0)

{
}
like image 894
user3009750 Avatar asked Sep 02 '25 10:09

user3009750


1 Answers

You can use OnInitDialog () to set any dialog values before the dialog displays. There are multiple ways to accomplish it. Here are two...

  1. You can use SetWindowText to insert a string value into the control.
  2. Define the control with a member variable that accepts a CString value. Assign a default value to the variable. OnInitDialog should handle updating the field.
like image 98
rrirower Avatar answered Sep 05 '25 02:09

rrirower