第一章 Hello,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 <math.h>
#include "Hello.h"

CMyApp myApp;

/////////////////////////////////////////////////////////////////////////
// CMyApp member functions

BOOL CMyApp::InitInstance()
{
    m_pMainWnd = new CMainWindow;//构造一个CMainWindow对象,并将地址复制到应用程序对象的m_pMainWnd数据成员中
    m_pMainWnd->ShowWindow(m_nCmdShow);//该窗口处于正常的非最小,非最大状态
    m_pMainWnd->UpdateWindow();//立即重新绘制窗口来完成由ShowWindow启动的作业
    return TRUE;//返回TRUE以允许应用程序继续进行,返回FALSE将关闭应用程序
}

/////////////////////////////////////////////////////////////////////////
// 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);    
}

 

posted @ 2021-11-17 20:48  梦之心  阅读(30)  评论(0编辑  收藏  举报