MFC 寫了一個Hello MFC

寫程序的,第一個程序,必定是 Hello World 之類的

把代碼貼出來




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"), 
		WS_OVERLAPPEDWINDOW, 
		CRect(100, 200, 500, 500));
}

void CMainWindow::OnPaint ()
{
	CPaintDC dc (this);

	CRect rect;
	GetClientRect (&rect);
	
	dc.DrawText (_T ("Hello, MFC"), -1, &rect,
		DT_SINGLELINE | DT_CENTER | DT_VCENTER);
	//dc.DrawText (_T ("Hello, MFC"), -1, &rect,
		//DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章