120 likes | 224 Views
C++ MFCs. CS 123/CS 231. MFC: Writing Applications for Windows. Classes in MFC make up an application framework Framework defines the skeleton of an application and supplies standard user-interface implementation that can be placed on the skeleton
E N D
C++ MFCs CS 123/CS 231
MFC: Writing Applications for Windows • Classes in MFC make up an application framework • Framework defines the skeleton of an application and supplies standard user-interface implementation that can be placed on the skeleton • Additional programming task: fill in the skeleton with things specific to your application
SDI and MDI • Single Document Interface (SDI) • allows only one open document frame window at a time • Multiple Document Interface (MDI) • allows multiple document frame windows to be open in the same instance of an application
Tools • AppWizard creates files for starter application • Resource editors to design UI elements visually • Class Wizard to connect these elements to code • Class Library to implement application specific logic
Document, Views and Framework • Document – data object with which the user interacts in an editing session • derived from CDocument • View – window object through which the user interacts with a document • derived from CView • Frame Window – views are displayed inside document fram windows • derived from CFrameWnd
Document, Views and Framework • Document Template – orchestrates creation of documents, views, and frame windows • derived from CDocTemplate • creates and manages all documents of 1 type • Application Object – controls all of the objects above and specifies application behavior such as initialization and cleanup • Thread Objects – for multithreaded application • derived from CWinThread
Objects in a Running SDI Application Application Object Document Template Main Frame Window Document Tool Bar View Status Bar
GUI Programming • Use the AppWizard to create an MFC Application • For project type, select MFC AppWizard (exe) • Creates files that contain the application, document, view, and frame window classes; standard resources, including menus and optional toolbar; other required windows files; optional .RTF file containing standard windows help topics
GUI Programming • Use ClassWizard to Manage Classes and Windows Messages • Create handler functions for windows messages and commands • Create and manage classes • Create class member variables • Create OLE Automation methods and properties • Create database classes, etc
GUI Programming • Use Resource Editors to Create and Edit Resources • Create and edit menus, dialog boxes, custom controls, accelarator keys, bitmaps, icons, cursors, …
Messages • Applications running windows are message driven • User actions and events cause Windows to send messages to windows in the program • Ex: Mouse actions • mouse click sends WM_LBUTTONDOWN • release sends WM_LBUTTONUP
Messages • Large part of programming task is choosing which messages to map to which objects, and implement the mapping • Class Wizard will create empty message handler member functions • Use source editor to implement the body of the handler