MFC的六大关键技术:

1)MFC程序的初始化过程

2)消息映射

3)运行时类型识别(RTTI)

4)动态创建

5)永久保存

6)消息传递

一、MFC的初始化过程:

MFC的架构组成:

1.要有CWinApp的派生类

2.必须在全局区定义一个派生类的对象

3.在CWinApp派生类中必须对InitInstance()函数进行重写

【在MFC软件工程中,以APP类中的InitInstance()函数作为主函数,连接MFC的平台使用static Library静态链接库】

#include "stdafx.h"

class CMyApp:public CWinApp
{
virtual BOOL InitInstance()
{
AfxMessageBox("xx");
return TRUE;
}
};
CMyApp theApp;
/*
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MessageBox(NULL,"Win32测试MFC程序","测试",0);
return 0;
}
*/

消息映射机制:
1.必须使用类向导建立一个窗口类(CWin)的派生类
2.必须建立派生类的对象,来接受客户界面返回的消息
//在窗口派生类中,每个消息都与一个成员函数相对应
3.消息映射函数,必须通过类向导(ClassWizard)建立

 

Win32的消息处理机制:

#include "stdafx.h"
BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
if(uMsg==WM_COMMAND)
{
if(LOWORD(wParam)==IDCANCEL)
{
EndDialog(hwndDlg,IDCANCEL);
return TRUE;
}
}
if(uMsg==WM_LBUTTONDOWN)
{
int x=LOWORD(lParam);
int y=HIWORD(lParam);
char ch[];
sprintf(ch,"(%3d,%3d)",x,y);
//MessageBox(NULL,ch,"",MB_OK);
SetWindowText(hwndDlg,ch);
}
if(uMsg==WM_MOUSEMOVE)
{
int x=LOWORD(lParam);
int y=HIWORD(lParam);
char ch[];
sprintf(ch,"(%3d,%3d)",x,y);
//MessageBox(NULL,ch,"",MB_OK);
SetWindowText(hwndDlg,ch);
}
return FALSE; } int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
//MessageBox(NULL,"Win32测试MFC程序","测试",0);
DialogBox(hInstance,(LPCSTR)IDD_DIALOG1,NULL,DialogProc);
return ; }

 MFC的消息处理机制

//theApp:

#include "stdafx.h"
#include"MainDlg.h"
class MyApp:public CWinApp
{
virtual BOOL InitInstance( )
{
//AfxMessageBox("cc",NULL,MB_OK);
//CDialog *dlg=new CDialog(IDD_DIALOG1);
//dlg->DoModal();
MainDlg *dlg=new MainDlg();
dlg->DoModal();
return TRUE;
}
};
MyApp theApp;
//MainDlg派生类
#include "stdafx.h"
#include "MainDlg.h" #ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif /////////////////////////////////////////////////////////////////////////////
// MainDlg dialog
MainDlg::MainDlg(CWnd* pParent /*=NULL*/)
: CDialog(MainDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(MainDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
} void MainDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(MainDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
} BEGIN_MESSAGE_MAP(MainDlg, CDialog)
//{{AFX_MSG_MAP(MainDlg)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP() /////////////////////////////////////////////////////////////////////////////
// MainDlg message handlers
BOOL MainDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//Title
CDialog::SetWindowText("测试");
//Icon
HICON hicon=LoadIcon(AfxGetInstanceHandle(),(LPCSTR)IDI_ICON1);
CDialog::SetIcon(hicon,TRUE);
return TRUE;
}
void MainDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default CDialog::OnLButtonDown(nFlags, point);
CString str;
str.Format("(%d,%d)",point.x,point.y);
if(MK_SHIFT&nFlags)
str+="按下了Shift键";
if(MK_CONTROL&nFlags)
str+="按下了Ctrl键";
if(MK_LBUTTON&nFlags)
str+="按下了鼠标左键";
if(MK_MBUTTON&nFlags)
str+="按下了鼠标中键";
if(MK_RBUTTON&nFlags)
str+="按下了鼠标右键";
AfxMessageBox(str);
//CDialog::GetDlgItemText(IDC_TEXT_COORD,str);
}
void MainDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default CDialog::OnRButtonDown(nFlags, point);
CDialog::OnLButtonDown(nFlags, point);
CString str;
str.Format("(%d,%d)",point.x,point.y);
if(MK_SHIFT&nFlags)
str+="按下了Shift键";
if(MK_CONTROL&nFlags)
str+="按下了Ctrl键";
if(MK_LBUTTON&nFlags)
str+="按下了鼠标左键";
if(MK_MBUTTON&nFlags)
str+="按下了鼠标中键";
if(MK_RBUTTON&nFlags)
str+="按下了鼠标右键";
AfxMessageBox(str);
}
void MainDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default CDialog::OnMouseMove(nFlags, point);
CString str;
str.Format("(%d,%d)",point.x,point.y);
GetDlgItemText(IDC_TEXT_COORD,str);
}

MFC架构的更多相关文章

  1. 1.MFC架构分析

    1.架构代码文件的结构 主要由四个部分组成 1.资源文件Resource.h:主要定义资源的ID 2.预编译文件:stdafx.h 可以用来解决头文件包含冲突的问题,定义一些需要全局性包含的文件. 3 ...

  2. 流程图浅析MFC架构

    http://blog.csdn.net/qq2399431200/article/details/9035315

  3. 进入MFC讲坛的前言(五)

    框窗.视图和文档及其关系 MFC架构的另外一个特色是它的框窗.视图和文档这个三位一体的结构,它是一个典型的MVC(Model.View and Controler)结构.严格的讲,框窗不属于MVC中的 ...

  4. vs2015c++/MFC入门知识全集/实例规范书籍视频下载孙鑫c++对话框计算器基础控件使用教程系列

    VIP教程可免费看.可免费下载前部分试看教程地址:http://dwz.cn/4PcfPk免费下载地址:http://dwz.cn/mfc888 本课程目录 67章 [MFC项目开发第01天]Wind ...

  5. vc++MFC开发上位机程序

    用vc++MFC开发过不少跟单片机通讯的上位机程序了.搞懂了MFC架构,开发还是很快的,与底层单片机程序通讯,可以用串口.usb.网络.短信形式.串口现在用的越来越少了,一般电脑跟单片机在一块,使用串 ...

  6. BCGcontrolBar(一) MFC界面库简介

    原帖地址:http://blog.csdn.net/zw514159799/article/details/9148385 英文原文:http://www.bcgsoft.com/bcgcontrol ...

  7. MFC 学习笔记

    MFC 学习笔记 一.MFC编程基础: 概述: 常用头文件: MFC控制台程序: MFC库程序: 规则库可以被各种程序所调用,扩展库只能被MFC程序调用. MFC窗口程序: 示例: MFC库中类的简介 ...

  8. 在VC6中基于dll开发插件用于各种图片显示(BMP/TGA/JPG/GIF/PNG/TIF/ICO/WMF/EMF/...)

    一.图片显示 图片显示的方法: 1.  直接写程序 2.  第3方库 3.  调用COM组件的IPicture接口 4.  使用MFC的CPictureHolder类 5.  使用GDI+的CImag ...

  9. windows程序设计(二)

    MFC架构组成 1.CWinApp的派生类 2.必须在全局区定义一个派生类的对象 3.在CWinApp派生类内必须要有InitInstance虚函数的重写函数 在MFC软件工程以App类中的InitI ...

随机推荐

  1. JStack分析cpu消耗过高问题

    Mark一下, 今天确实用这个方法找到了问题 http://www.iteye.com/topic/1114219 1. top找到目标进程,记下pid 2. top –p pid, 并用shift+ ...

  2. 【转】C#高性能大容量SOCKET并发(二):SocketAsyncEventArgs封装

    http://blog.csdn.net/sqldebug_fan/article/details/17557341 1.SocketAsyncEventArgs介绍 SocketAsyncEvent ...

  3. 【转】将 azw3 格式转换为 mobi 格式并保持原有排版格式

    小伙伴多次向 Kindle 伴侣提出一个问题,那就是通过 Calibre 将排版精美的 azw3 格式电子书转换成 mobi 格式后推送到 Kindle,排版格式会发生很大的变化,比如行距过窄.内嵌字 ...

  4. java new synchronized

    java provides the synchronized keyword for synchronizing thread access to critical sections. Because ...

  5. 蓝牙BLE MTU规则与约定

    1. 问题引言: 想在gatt client上(一般是手机上)传输长一点的数据给gatt server(一般是一个Bluetooth smart设备,即只有BLE功能的设备),但通过 writeCha ...

  6. php--yii框架中的ajax分页与yii框架自带的分页

    要想使用Yii分页类 第一步:在控制器层加载分页类 use yii\data\Pagination; 第二步: 使用model层查询数据,并用分分页,限制每页的显示条数 $data = Zhao::f ...

  7. 检测电脑安装的net framework版本

    https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx To find .NET Framework versions by ...

  8. TEST指令

    In the x86 assembly language, the TEST instruction performs a bitwise AND on two operands. The flags ...

  9. 设计模式:组合模式(Composite)

    定   义:将对象组合树形结构以表示“部分-整体”的层次结构.组合模式使得用户对单个对象和组合对象使用具有一致性. 结构图: Component类: abstract class Component ...

  10. One Time Auth

    One Time Auth One-time authentication (shortened as OTA) is a new experimental feature designed to i ...