MFC第一个程序Hello!
时间:2008-06-08 06:32:46 来源:程序人生 作者:
AD
#include <afxwin.h>
class CMyApp : public CWinApp {
public:
virtual BOOL InitInstance();
};
class CMainWindow : public CFrameWnd {
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
CMyApp myApp;
//-------------member functions---------
BOOL CMyApp::InitInstance() {
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
//--------CMainWindow message map-------
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
//-----------member functions------------
CMainWindow::CMainWindow() {
Create(NULL,"The Hello Application",WS_OVERLAPPEDWINDOW);
}
void CMainWindow::OnPaint() {
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText("Hello,MFC",-1,&rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
//这是一个MFC的简单程序.但是也较完整的表现了MFC的编程结构.
class CMyApp : public CWinApp {
public:
virtual BOOL InitInstance();
};
class CMainWindow : public CFrameWnd {
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
CMyApp myApp;
//-------------member functions---------
BOOL CMyApp::InitInstance() {
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
//--------CMainWindow message map-------
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
//-----------member functions------------
CMainWindow::CMainWindow() {
字串9
Create(NULL,"The Hello Application",WS_OVERLAPPEDWINDOW);
}
void CMainWindow::OnPaint() {
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText("Hello,MFC",-1,&rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
//这是一个MFC的简单程序.但是也较完整的表现了MFC的编程结构.
上一篇:C++中Reference与指针(Pointer)的使用对比 下一篇:没有了
文章评论
共有 0位网友发表了评论