读书人

visual studio 2012 怎么在win32里加

发布时间: 2013-04-26 16:27:53 作者: rapoo

visual studio 2012 如何在win32里加入mfc元素
我在用visual studio 2012做一个win32应用,要用到mfc的东西,不知道怎么添加微软基础类。还望指导,谢谢 Visual?Studio 微软 MFC win32 应用
[解决办法]
包含afxwin.h之类的头文件,然后在项目配置中选择使用MFC即可.
推荐"Programming Windows with MFC"这本书.

Hello.h
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();
protected:
afx_msg void OnPaint ();
DECLARE_MESSAGE_MAP ()
};

Hello.cpp
#include <afxwin.h>
#include "Hello.h"
CMyApp myApp;
/////////////////////////////////////////////////////////////////////////
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_PAINT ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
Create (NULL, _T ("The Hello Application"));
}
void CMainWindow::OnPaint ()
{
CPaintDC dc (this);
CRect rect;
GetClientRect (&rect);
dc.DrawText (_T ("Hello, MFC"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}

读书人网 >C++

热点推荐