以前对于MFC的了解十分肤浅,只知道MFC = Microsoft Foundation Class,后来还道听途说了很多关于她的风流韵事。有人说她如维纳斯一般美丽,也有人说她和犹大一般丑恶。现在为了手头上的事情,我要从新认识这位也许风华不在的女子了,不管她长得如何,我都得去揭开她那对于我来说神秘的面纱。
还是从打招呼开始吧,以免把她吓着了。于是,我战战兢兢的跟MFC say hello了。
MyApp.h: class CMyApp : public CWinApp { public: virtual BOOL InitInstance(); }; // frame window class class CMyFrame : public CFrameWnd { public: CMyFrame(); protected: // "afx_msg" indicates that the function is part // of the MFC library message dispatch system afx_msg void OnPaint(); DECLARE_MESSAGE_MAP() }; MyApp.cpp:
#include <afxwin.h> // MFC library header file declares base classes #include "myapp.h"
CMyApp theApp; // the one and only CMyApp object
BOOL CMyApp::InitInstance() { m_pMainWnd = new CMyFrame(); m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow(); return TRUE; }
BEGIN_MESSAGE_MAP(CMyFrame, CFrameWnd) ON_WM_PAINT() END_MESSAGE_MAP()
CMyFrame::CMyFrame() { Create(NULL, "MYAPP Application"); }
void CMyFrame::OnPaint() { CPaintDC dc(this); dc.TextOut(0, 0, "Hello, MFC!"); } |
|