VC++深入详解第三章

MFC(Microsoft Foundation Class)

共同的基类:CWnd类

3.MFC大致流程:
CTestApp theApp;//构造全局对象
WinMain()
{
 AfxWinMain();//调用下面的函数
}

AfxWinMain()
{
 CWinThread* pThread = AfxGetThread();
 CWinApp* pApp = AfxGetApp();
 pThread->Initinstance();//初始化工作和注册窗口类,窗口显示和更新
 pThread->Run();//消息循环
}

theApp构造函数CTestApp创建父构造函数CWinApp

Afx前缀的都是全局函数

Initlnstance函数(virtual)
{
 CSingleDocTemplate* pDocTemplate;
//CSingleDocTemplate类定义了一个文档模板用于实现单文档界面(SDI)。一个SDI应用程序使用主框架窗口来显示一个文档;一次只能打开一个文档。 
 pDocTemplate = new CSingleDocTemplate(
  IDR_MAINFRAME,
  RUNTIME_CLASS(CTestDoc),
  RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  RUNTIME_CLASS(CTestView));
 AddDocTemplate(pDocTemplate);

 // Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 // Dispatch commands specified on the command line
 if (!ProcessShellCommand(cmdInfo))
  return FALSE;

 // The one and only window has been initialized, so show and update it.
 m_pMainWnd->ShowWindow(SW_SHOW);
 m_pMainWnd->UpdateWindow();


4.如何在单文档文件中显示一个CButton的对象?
在CMainFrame::OnCreate()中定义一个CButton的对象btn;然后调用btn.Create("维新",WS_DISABLED   |WS_CHILD | WS_VISIBLE | BS_AUTO3STATE,
  CRect(0,0,300,100),/*GetParent(),*/this,123);
注意点:
     (1).此处btn不能是局部变量,否则它的生命周期太短,将不能显示。
     (2).在create函数的第二个参数中加入WS_VISIBLE 参数才行。否则必须调用ShowWindow
也可以在view的OnCreate消息响应函数中加入
     (3).CButton类的定义头文件在afxwin.h中,而stdafx.h包含了afxwin.h,所以可以直接使用。因为MFC中的每一个类中都有#include "stdafx.h"的声明

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值