Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /

Similar presentations


Presentation on theme: "Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /"— Presentation transcript:

1 Introduction to MFC

2 Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document / View architecture MFC – Microsoft Foundation Classes API – Application Programming Interface GUI – Graphical User Interface DLL – Dynamic Link Libraries

3 MFC MFC is designed for event based programs Traditional applications are executed top to bottom

4 MFC basics

5 MFC basics - 2003

6 MFC basics - 2005

7 MFC basics

8 MFC Application structure VS creates automatically: –MyApp.cpp / h –MainFrame.cpp / h –MyAppDoc.cpp / h –MyAppView.cpp / h

9 MFC Application structure VS creates automatically: –MyApp.cpp / h – message loop, no data –MainFrame.cpp / h – main interface –MyAppDoc.cpp / h – data manipulation –MyAppView.cpp / h – visualization

10 What we need Events / Messages Dialogs GUI – data input and output

11 MFC messages and commands The 4 files have the following lines BEGIN_MESSAGE MAP … END_MESSAGE_MAP Every class can take care of messages They can be defined manually or automatically Messages represent OS events

12 Messages WM_CHARA character is input from the keyboard. WM_COMMANDThe user selects an item from a menu, or a control sends a notification to its parent. WM_CREATEA window is created. WM_DESTROYA window is destroyed. WM_LBUTTONDOWNThe left mouse button is pressed. WM_LBUTTONUPThe left mouse button is released. WM_MOUSEMOVEThe mouse pointer is moved. WM_PAINTA window needs repainting. WM_QUITThe application is about to terminate. WM_SIZEA window is resized.

13 Adding messages View  Class View Choose appropriate class Right click on the class  Properties

14 Messages BEGIN_MESSAGE MAP ON_WM_DESTROY() END_MESSAGE MAP void MyAppView::OnDestroy() { CView::OnDestroy(); // TODO: Add your message handler code here }

15 Commands Commands come from menus Add command to menu –View  Resource View  IDR_MyAppType Add handler –Menu  Right Click  Add Event Handler –Choose class

16 Commands

17

18

19 BEGIN_MESSAGE MAP ON_COMMAND(ID_DDD_DDD, OnDddDdd) END_MESSAGE MAP void MyAppView::OnDddDdd() { // TODO: Add your message handler code here }

20 Toolbar Another way to use menu View  Resource View  toolbar

21 Toolbar Add new icons Change the appearance of icons Add new icons Change ID of icons (add commands manually to the CPP/H files)

22 Controls Special windows for input / output Exists in View  Resources Control TypeWNDCLASSMFC Class Buttons"BUTTON"CButton List boxes"LISTBOX"CListBox Edit controls"EDIT"CEdit Combo boxes"COMBOBOX"CComboBox Scroll bars"SCROLLBAR"CScrollBar Static controls"STATIC"CStatic

23 Dialog Boxes Windows that pop up to obtain input Modal dialogs disables parent window Modeless dialog does not disable parent Create dialog in resources Add desired controls Add class

24 Dialog boxes

25 Dialog usage In a file: CMyDialog dlg; if ( dlg.DoModal() == IDOK ) { // The user clicked OK; do something ! }

26 Dialog usage Get data from dialog –Define class variable –Put the values from controls into the variables –Use the variables in the main file –Automatic support in Visual Studio void CMyDialog::DoDataExchange( CDataExchange* pDX){ DDX_Text (pDX, IDC_NAME, m_strName); DDX_Text (pDX, IDC_PHONE, m_strPhone); } Class variable

27 DDX Functions DDX FunctionDescription DDX_TextAssociates a BYTE, an int, a short, a UINT, a long, a DWORD, a CString, a string, a float, a double, a COleDateTime, or a COleCurrency variable with an edit control. DDX_CheckAssociates an int variable with a check box control. DDX_RadioAssociates an int variable with a group of radio buttons. DDX_LBStringAssociates a CString variable with a list box. DDX_LBStringExactAssociates a CString variable with a list box.

28 Common Dialogs ClassDialog Type(s) CFileDialogOpen and Save As dialog boxes. CPrintDialogPrint and Print Setup dialog boxes. CPageSetupDialogPage Setup dialog boxes. CFindReplaceDialogFind and Replace dialog boxes. CColorDialogColor dialog boxes. CFontDialogFont dialog boxes.

29 MFC & Open Inventor We will create MFCViewer.cpp Enter MFCViewer.cpp –SoWin::init(""); into InitInstance(); Enter MFCViewerView.h –#include –SoWinExaminerViewer * viewer; Modify the constructor –CMFCViewerView::CMFCViewerView() { viewer = NULL; } Modify the destructor –CMFCViewerView::CMFCViewerView() { if (viewer != NULL) delete viewer; }

30 MFC & Open Inventor void CMFCViewerView::OnDraw(CDC* pDC) CMFCViewerDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (viewer == NULL) { viewer = new SoWinExaminerViewer( m_hWnd ); viewer->setDecoration(FALSE); //Try TRUE viewer  setSceneGraph(pDoc  root); }

31 MFC & Scene Graph Enter MFCViewDoc.h –class SoSeparator; above CMFCViewDoc definition –Insert SoSeparator *root into CMFCViewDoc Include files into MFCViewerDoc.cpp Modify constructor & destructor like in View Create scene in OnNewDocument() Go to CMFCViewerView::OnDraw() SoSeparator *root = GetDocument()->root; viewer->setSceneGraph(root);


Download ppt "Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /"

Similar presentations


Ads by Google