MFC架构
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.MFC架构分析
1.架构代码文件的结构 主要由四个部分组成 1.资源文件Resource.h:主要定义资源的ID 2.预编译文件:stdafx.h 可以用来解决头文件包含冲突的问题,定义一些需要全局性包含的文件. 3 ...
- 流程图浅析MFC架构
http://blog.csdn.net/qq2399431200/article/details/9035315
- 进入MFC讲坛的前言(五)
框窗.视图和文档及其关系 MFC架构的另外一个特色是它的框窗.视图和文档这个三位一体的结构,它是一个典型的MVC(Model.View and Controler)结构.严格的讲,框窗不属于MVC中的 ...
- vs2015c++/MFC入门知识全集/实例规范书籍视频下载孙鑫c++对话框计算器基础控件使用教程系列
VIP教程可免费看.可免费下载前部分试看教程地址:http://dwz.cn/4PcfPk免费下载地址:http://dwz.cn/mfc888 本课程目录 67章 [MFC项目开发第01天]Wind ...
- vc++MFC开发上位机程序
用vc++MFC开发过不少跟单片机通讯的上位机程序了.搞懂了MFC架构,开发还是很快的,与底层单片机程序通讯,可以用串口.usb.网络.短信形式.串口现在用的越来越少了,一般电脑跟单片机在一块,使用串 ...
- BCGcontrolBar(一) MFC界面库简介
原帖地址:http://blog.csdn.net/zw514159799/article/details/9148385 英文原文:http://www.bcgsoft.com/bcgcontrol ...
- MFC 学习笔记
MFC 学习笔记 一.MFC编程基础: 概述: 常用头文件: MFC控制台程序: MFC库程序: 规则库可以被各种程序所调用,扩展库只能被MFC程序调用. MFC窗口程序: 示例: MFC库中类的简介 ...
- 在VC6中基于dll开发插件用于各种图片显示(BMP/TGA/JPG/GIF/PNG/TIF/ICO/WMF/EMF/...)
一.图片显示 图片显示的方法: 1. 直接写程序 2. 第3方库 3. 调用COM组件的IPicture接口 4. 使用MFC的CPictureHolder类 5. 使用GDI+的CImag ...
- windows程序设计(二)
MFC架构组成 1.CWinApp的派生类 2.必须在全局区定义一个派生类的对象 3.在CWinApp派生类内必须要有InitInstance虚函数的重写函数 在MFC软件工程以App类中的InitI ...
随机推荐
- 【转】设计模式(三)建造者模式Builder(创建型)
(http://blog.csdn.net/hguisu/article/details/7518060) 1. 概述 在软件开发的过程中,当遇到一个"复杂的对象"的创建工作,该对 ...
- 【Demo】 生成二维码 和 条形码
条形码 和 二维码 对比 一维条形码只是在一个方向(一般是水平方向)表达信息,而在垂直方向则不表达任何信息,其一定的高度通常是为了便于阅读器的对准. 在水平和垂直方向的二维空间存储信息的条形码, 称为 ...
- CC Debugger调试下载接口
调试下载接口: 引脚序号 引脚名称 相关说明 1 GND 地线 2 VDD 目标板电源正端 3 DC 调试-时钟线 4 DD 调试-数据线 5 CSn 下载-片选线(低电平有效) 6 SCLK 下载- ...
- PHP 日期比较
$temptime = mktime(8,2,12,4,4,2014);$dt1 = date("Y-m-d",time());$dt2 = date("Y-m-d&qu ...
- 转:php 获取时间今天明天昨天时间戳
<?php echo "今天:".date("Y-m-d")."<br>"; echo "昨天:".d ...
- Jquery调用webService的四种方法
1.编写4种WebService方法 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(Conf ...
- [LeetCode] Substring with Concatenation of All Words(good)
You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...
- Selenium2学习-005-WebUI自动化实战实例-003-三种浏览器(Chrome、Firefox、IE)启动脚本源代码
此文主要通过 三种浏览器(Chrome.Firefox.IE)启动脚本 功能,进行 Selenium2 三种浏览器启动方法的实战实例讲解.文中所附源代码于 2015-01-18 20:33 亲测通过, ...
- iOS GCD简单使用
Grand Central Dispatch (GCD) 1)运行在主线程的Main queue,通过dispatch_get_main_queue获取. /*!* @function dispatc ...
- iOS项目的目录结构和开发流程(Cocoa China)
目录结构 AppDelegate Models Macro General Helpers Vendors Sections Resources 一个合理的目录结构首先应该是清晰的,让人一眼看上去 ...