A Simple Window |
|
The Document/View architecture provides its own technique of creating a program. An application is made of two primary sections: The application class and the frame.
|
The application class allows you to notify the operating system that your application exists, that your application needs memory and that it may use some resources. Based on this, to start an application, you must create your own class and derive it from the MFC's CWinApp. Here is an example: #include <afxwin.h> class CExerciseApp : public CWinApp { }; If you have done Win32 programming before, you may know that each application works by creating an instance. In the same way, if you create a Document/View architecture, when the application comes up, it must create an instance. To support this, the CWinApp class is equipped with the Boolean InitInstance() method that you should implement in your application. Here is an example: class CExerciseApp : public CWinApp { BOOL InitInstance() { return TRUE; } }; The frame allows you to show the borders and probably the contents of the (main) window of your application. To create a frame, you can derive a class from the MFC's CFrameWnd class and you should implement its (default) constructor. In the definition of the constructor of your class, you should call the Create() method that allows you to formally create a frame. Only two pieces of information are required to create a frame, the name of the class, which should be passed as NULL, and the name of the window, which is the string that will be shown on the title bar. After defining the frame class,, you should instantiate in the InitInstance() method of your application. |
Practical Learning: Creating a Simple Window |
|