MFC Program or Control Source and Header Files


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at MFC Program or Control Source and Header Files.

The following files are created when you create an MFC project in Visual Studio, depending on the options you select for the project you create. For example, your project contains Projnamedlg.cpp and Projnamedlg.h files only if you create a dialog-based project or class.

All of these files are located in the Projname directory, and in either the Header Files (.h files) folder or Source Files (.cpp files) folder in Solution Explorer.

File nameDescription
Projname.hThe main include file for the program or DLL. It contains all global symbols and #include directives for other header files. It derives the CPrjnameApp class from CWinApp and declares an InitInstance member function. For a control, the CPrjnameApp class is derived from COleControlModule.
Projname.cppThe main program source file. It creates one object of the class CPrjnameApp, which is derived from CWinApp, and overrides the InitInstance member function.

For executables, CPrjnameApp::InitInstance does several things. It registers document templates, which serve as a connection between documents and views; creates a main frame window; and creates an empty document (or opens a document if one is specified as a command-line argument to the application).

For DLLs and ActiveX (formerly OLE) controls, CProjNameApp::InitInstance registers the control's object factory with OLE by calling COleObjectFactory::RegisterAll and makes a call to AfxOLEInit. In addition, the member function CProjNameApp::ExitInstance is used to unload the control from memory with a call to AfxOleTerm.

This file also registers and unregisters the control in the Windows registration database by implementing the DllRegisterServer and DllUnregisterServer functions.
Projnamectrl.h, Projnamectrl.cppDeclare and implement the CProjnameCtrl class. CProjnameCtrl is derived from COleControl, and skeleton implementations of some member functions are defined that initialize, draw, and serialize (load and save) the control. Message, event, and dispatch maps are also defined.
Projnamedlg.cpp, Projnamedlg.hCreated if you choose a dialog-based application. The files derive and implement the dialog class, named CProjnameDlg, and include skeleton member functions to initialize a dialog and perform dialog data exchange (DDX). Your About dialog class is also placed in these files instead of in Projname.cpp.
Dlgproxy.cpp, Dlgproxy.hIn a dialog-based program, the implementation and header file for the project's Automation proxy class for the main dialog. This is only used if you have chosen Automation support.
Projnamedoc.cpp, Projnamedoc.hDerive and implement the document class, named CProjnameDoc, and include skeleton member functions to initialize a document, serialize (save and load) a document, and implement debugging diagnostics.
Projnameset.h/.cppCreated if you create a program that supports a database and contains the recordset class.
Projnameview.cpp, Projnameview.hDerive and implement the view class, named CProjnameView, which is used to display and print the document data. The CProjnameView class is derived from one of the following MFC classes:

- CEditView
- CFormView
- CRecordView
- COleDBRecordView
- CTreeView
- CListView
- CRichEditView
- CScrollView
- CView
- CHTMLEditView

The project's view class contains skeleton member functions to draw the view and implement debugging diagnostics. If you have enabled support for printing, then message-map entries are added for print, print setup, and print preview command messages. These entries call the corresponding member functions in the base view class.
ProjnamePropPage.h, ProjnamePropPage.cppDeclare and implement the CProjnamePropPage class. CProjnamePropPage is derived from COlePropertyPage and a skeleton member function, DoDataExchange, is provided to implement data exchange and validation.
IPframe.cpp, IPframe.hCreated if the Mini-Server or Full-Server option is selected in the application wizard's Automation Options page (step 3 of 6). The files derive and implement the in-place frame window class, named CInPlaceFrame, used when the server is in place activated by a container program.
Mainfrm.cpp, Mainfrm.hDerive the CMainFrame class from either CFrameWnd (for SDI applications) or CMDIFrameWnd (for MDI applications). The CMainFrame class handles the creation of toolbar buttons and the status bar, if the corresponding options are selected in the application wizard's Application Options page (step 4 of 6). For information on using CMainFrame, see The Frame-Window Classes Created by the Application Wizard.
Childfrm.cpp, Childfrm.hDerive the CChildFrame class from CMDIChildWnd. The CChildFrame class is used for MDI document frame windows. These files are always created if you select the MDI option.

File Types Created for Visual C++ Projects
ATL Program or Control Source and Header Files
CLR Projects