Monday, 4 March 2013

Activity 3: Dialog boxes


Activity 3: Dialog boxes
In this program we will use a dialog box to allow a user to input data and use that data to
display a personalised message on the main client area of the screen.
·  Start a new program by selecting New in the File menu, select the MFC AppWizard (exe)
entry under the projects tab in the New dialog box.
·  Give the new program the name ComputerConversation in the Project name box,
choose a location and click OK to start the MFC AppWizard. In Step 1, select Single
document. Then accept the defaults for all the other steps.
·  To create an input dialogue box, select the Resource item from the Insert menu. This
opens the Insert Resource box. Select the Dialog entry and click the new button. This
opens the Dialog box editor.
·  Add a label, right click and open its properties. Change the caption to “Type in your
name please.”
·  Add an edit box underneath and a button (with the caption “Talk to me!”).
·  Choose Class Wizard from the View menu to create a new dialog box class. Choose
create a new class and name it Dlg. Click OK. To connect an event handler to the
button, select IDC_BUTTON1 and double click the BN_CLICKED entry in the Messages
box. This creates the new member function OnButton1().
·  Now change to the Member Variables tab of the Class Wizard, select IDC_EDIT1 and
click the Add Variable button. Create the variable m_text of the value category as type
CString.
·  Connect m_text to the IDC_EDIT control using the DDX_text() method 0f the
DoDataExchange() class. Add the bold code to dlg.cpp.
void Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(Dlg)
DDX_Text(pDX, IDC_EDIT1, m_text);
//}}AFX_DATA_MAP
}

No comments:

Post a Comment