MFC第一篇

 1.1  MFC基本认识

Afx.h   //MFC 基本类框架

Afxwin.h //MFC 程序框架

CwinApp //程序对象

CFrame //程序框架

InitInstance();//初始化函数

//消息入口

DECLARE_MESSAGE_MAP()(在CFrame中定义)

//消息处理开始

BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)

    //绘画

    ON_WM_PAINT()

    //消息结束

 END_MESSAGE_MAP()

1.2  MFC创建基本步骤

(1)     继承CwinApp  定义绘制窗口函数OnPaint

(2)     继承CFrame 定义初始化函数 Initistance

(3)     实现CwinApp构造函数创建窗口(Create(NULL,title))

(4)     实现OnPaint函数绘制程序GUI

(5)     实现初始化函数Initinstance (将CwinApp保存到m_pMainWind中负责无法运行)

 

1.3 实战1 第一个MFC程序

 

App.h  

#ifndef   _AFXDLL

#define   _AFXDLL

#endif

#include <afx.h>

#include <afxwin.h>

class SelfApp:public CWinApp

{

public :

    //初始化函数

    virtual BOOL InitInstance();

 

};

 

class CMainWindow :public CFrameWnd

{

public:

    CMainWindow();

protected:

    afx_msg void OnPaint();

    //消息入口

    DECLARE_MESSAGE_MAP()

};

Appi.cpp

#include "app.h"

SelfApp app;

CMainWindow  *  mainwnd;

//实现函数及构造函数

BOOL  SelfApp::InitInstance()

{

    mainwnd  =  new CMainWindow;

    mainwnd->ShowWindow(m_nCmdShow);

    mainwnd->UpdateWindow();

 

    m_pMainWnd = mainwnd;

    return TRUE;

}

//消息处理开始

BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)

    //绘画

    ON_WM_PAINT()

    //消息结束

    END_MESSAGE_MAP()

    CMainWindow::CMainWindow()

    {

        //创建窗口

        Create(NULL,TEXT("The Application"));

    }

    void CMainWindow::OnPaint()

    {    //绘制笔

        CPaintDC dc(this);

        CRect rect;

        GetClientRect(&rect);

       //绘制文本

        dc.DrawText(__T("This is MFC application"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);

    }

转载于:https://my.oschina.net/u/3768017/blog/1782815

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值