MFC Dialog Application Steps to Build MFC Dialog in VS.Net 2003

Report
MFC Dialog Application
Steps to Build MFC Dialog in VS.Net 2003
Instructor : Dr.James Fawcett
Prepared by : Priyaa Nachimuthu
Summer 2004
[email protected]
Text Generator in action
Intent
• Accept text entered into the top EditBox.
• Transfer text to the second EditBox as it is typed – illustrates use of
text controls.
• When user hits Add button the contents of the top edit box will be
transferred to a list box.
Note: You must #include “stdafx.h” at the top of every *.cpp file in
your server implementation.
Construction Steps - Summary
•
•
•
•
•
•
•
Run Application Wizard
Select MFC Application project
Select Dialog-based
Pull controls from control palette onto dialog in Resource View.
Add message handlers for every event you want to handle.
– You can either right-click on dialog class in Class View to add
handler
– Or you double click on the control you want to handle, e.g., EditBox
or Button.
– When you double click, you get a handler for the most common
message for that control. That may or may not be what you want.
– You get more control by using the first method. The second
method is faster.
Add code in message handlers, perhaps by calling a server module
providing the computational engine for your interface.
Compile, Edit, and Run repeatedly until you get the behavior and
appearance you want.
Resulting Dialog Structure
CWinThread
CWinApp
CDialogRecipeApp
CWnd
Object stored locally in
CDialogRecipeApp::InitInstance()
CDialog
CDialogRecipeDlg
Convert Server
Construction Steps – Creating a MFC Project
•
•
Create a blank solution and add a new project
Select Visual C++ Projects - MFC Application
Construction Steps – Application wizard
• You will be directed to MFC Application wizard
Construction Steps – Application Type
• Select Dialog –based application
Construction Steps – UI Features
• Choose the desired user interface features
Construction Steps – Advanced Features
• Uncheck ActiveX controls if none is used in the
application
Construction Steps – Resource view
• On finish,App wizard directs to a resource editor
Construction Steps – Populating a dialog
•
Use tool box to populate dialog
Construction Steps – Adding a variable
•
Right click on the control (Edit Box) to add a variable
Construction Steps – Add variable wizard
•
Select the variable type,type in the variable name, and
choose category as value for Edit Box control
Construction Steps – Adding a variable
•
Right click on the control (List Box) to add a variable
Construction Steps – Add variable wizard
•
Select the variable type,type in the variable name, and
choose category as control for List Box control
Construction Steps – Adding an event handler
for a button control
•
Double click on the control or choose an event handler
from the control’s properties window
Construction Steps – Adding an event handler
for an Edit Box
•
Double click on the control or choose an event handler
from the control’s properties window
Construction Steps – Adding a Windows Message Handler
•
In the main dialog’s properties window,select the right
most Messages icon which lists all windows message
handlers
Construction Steps – Adding a Windows Message Handler
•
Choose a message handler ( WM_LBUTTONDOWN –
OnLButtonDown handler )
Construction Steps – Adding code for event handlers
•
Add code for event handlers in MFCDialogDemoDlg.cpp
Construction Steps – Adding code for OnOK event handler
•
Add code for event handlers in MFCDialogDemoDlg.cpp
Add Code, Compile, and Run

similar documents