Introduction to MFC - Explaining the File Names and Extending the Application
(Page 4 of 5 )
MFC_example.h – The main header file for the application; here the About dialog class is also defined.
MFC_example.cpp – The implementation file of the application. This class manages the New, Open, and Print Setup among the About dialog.
MainFrm.h – Yes, this exists under this name regardless of the name of the application. This defines the functions that will create the main window.
MainFrm.cpp – As you can predict, here we implement the upper header functions. This is the place where the main window is created, then the Status Bar, and the Toolbar or the splitter view, if that’s the case.
MFC_exampleDoc.h – Header file for opening, saving, and loading files.
MFC_exampleDoc.cpp - The implementation of the upper file. Here we manage the serialization process.
MFC_exampleView.h – This represents the header file for the window shown. An invisible territory (window) is positioned by MFC in the client area of the frame.
MFC_exampleView.cpp – This is the place where we manage the client area. If something needs to be updated, this class will be called. For example, if the client modifies something and the output date has to be updated, then these classes’ OnDraw function will be called. The Print command and the Print preview content is also placed in the default settings.
Stdafx.h – Include file for frequently used headers that aren’t changed often.
Stdafx.cpp – When we create a header we need to implement it, and this helps.
Resource.h – Here the resources are defined.
MFC_example.rc – The resource file containing the resources. For a start, it contains the status bar, toolbar, menu, about dialog box, and the icons of the application. For additional information on this subject I advise you to check out the third part of this series (as soon as it goes live, that is).
Now we will extend our application with some individual touches, so it’s the perfect time to demonstrate the way we can manage this. It’s all about modifying the parameters to which the window creation is called. For this we will venture into the Mainframe.cpp. Once in there, search for the following code snippet:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by //modifying
// the CREATESTRUCT cs
return TRUE;
}
Now you must know that the cs structure holds many parameters that will be transmitted forward when the window is created for the first time. It is safe to say that at the creation process when the message is sent, it’s time to create the window. This function will be called and a result will be returned carrying all the information that is required. So let’s alter the initial cs settings. After the comments add the following:
cs.cx = 720; // width of the new window
cs.cy = 780; // height of the new window
cs.x = 100; // initial position of the window, on the x axis
cs.y = 200; // on the y axis
Save the file and run the solution. Congratulations, we are damn good; you can already see the results happening in front of your eyes!
Next: Conclusion >>
More BrainDump Articles
More By Gabor Bernat