Sunday, February 12, 2012

A minimum MFC Windows Application

- In Start-up page of Microsoft Visual Studio 11, click New Project... to call-up application wizard.

- Select template of Visual C++ Win32 Project, with name of MFCminApplication, and click OK.
Create a new Visual C++ Win32 Project

- Click Next on the Application Settings screen.
Application Settings

- Check Empty project option, and click Finish.
Empty project

- After project created, click Project on the top menu, and select the project properties - MFCminApplication Properties...
MFCminApplication Properties...

- Select Configuration Properties -> General tab, select Use MFC in Shared DLL in Use of MFC property.
select Use MFC in Shared DLL

- Right click Source Files in Solution Explorer, -> Add -> Class to craete a new source file.
craete a new source file

- Select Visual C++ Class, and click Add.
Add a new Visual C++ Class

- Enter Class name of CMFCminApplication(both .h and .cpp file name will be generatedautomatically), with Base class of CWinApp, public Access. Finish.
Enter Class info

- You will be complained Bass class 'CWinApp' not found in the project. Click Yes to continue adding the class.
Bass class 'CWinApp' not found in the project.

- Modify the generated MFCminApplication.h and MFCminApplication.cpp:
MFCminApplication.h
#pragma once
#include <afxwin.h>
class CMFCminApplication :
 public CWinApp
{
public:
 virtual BOOL InitInstance();
};


MFCminApplication.cpp
#include "MFCminApplication.h"

class CMFCminFrameWnd :
 public CFrameWnd
{
public:
 CMFCminFrameWnd(){
  Create(0, L"Hello, Minimal MFC Application");
 }
};

BOOL CMFCminApplication::InitInstance(){
 m_pMainWnd = new CMFCminFrameWnd;
 m_pMainWnd->ShowWindow(m_nCmdShow);
 return TRUE;
}

CMFCminApplication myApplication;


- Finally, you can build and run the application.
The finalized project

- The minimal application change the title only!
The minimal MFC Application

No comments:

Post a Comment