C++程序设计-MFC简介

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

class CFrameWnd : public CWnd
标题栏、系统菜单、边框、最小 最大化 标题栏、系统菜单、边框、最小/最大化
class CView : public CWnd
1) 显示 打印的处理 OnDraw() 显示/打印的处理 2) 与用户进行交互操作(鼠标 键盘 鼠标/键盘 与用户进行交互操作 鼠标 键盘) OnLButtonDown/OnLButtonUp OnKeyDown … … 3) 系统重画 Invalidate(); UpdateWindow();
class CString LPCTSTR LPCSTR { public: CString(); CString(const CString& stringSrc); LPCSTR CString(TCHAR ch, int nRepeat = 1); 是单字节 void CString(LPCSTR lpsz); Func(LPCTSTR lpsz) CString(LPCWSTR lpsz); { CString str(lpsz); LPCWSTR CString(LPCSTR lpch, int nLength); int l=str.Length(); CString(LPCWSTR lpch, int nLength); 是双字节 } CString(const unsigned char* psz); 。。。 。。。
class CWinApp : public CCmdTarget
1) 获取应用程序的信息。 获取应用程序的信息。 2) 支持注册表 RegistryKey 3) 支持文档 Document Template
class CWnd : public CCmdTarget
1) 注册新窗口类。 注册新窗口类。 2) 创建和使用窗口 Create, CreateEx;
CSize SIZE
与CSize类似的类 : CPoint
typedef struct tagPOINT { LONG x; LONG y; } POINT, *PPOINT, *LPPOINT; class CPoint : public tagPOINT { public: CPoint(); CPoint(int initX, int initY); CPoint(POINT initPt); 。。。 。。。 };
C++程序设计教程
MFC简介
MFC简介
VC++分为 分为API和MFC两部分 分为 和 两部分 Win32 API(Application Programming Interface)类似于 类似于C 类似于 语言的库函数,提供诸如strcpy()、 语言的库函数,提供诸如 、 memset()、fopen()等函数。 等函数。 、 等函数 MFC ( Microsoft Foundation Class ) 微软基本类库,提供窗口 微软基本类库, (Windows)式程序编程框架。 )式程序编程框架。 通过MFC,我们可以构造基于窗口的应 通过 , 用程序,如对话框( )、单文档 用程序,如对话框(Dialog)、单文档 )、 (Single Document)和多文档 ) (Multiply Document)应用软件。 )应用软件。
1.
1. 2. 3. 4. 5. 6.
BOOL 布尔类型 (int型) 型 INT, UINT 与int有关类型 有关类型 CHAR,(UCHAR)BYTE 与char有关类型 有关类型8bit 有关类型 SHORT,(USHORT)WORD 与short有关类型 有关类型16bit 有关类型 LONG,(ULONG)DWORD 与long有关类型 有关类型32bit 有关类型 LONGLONG,ULONGLONG 64bit类型 类型 FLOAT : 类型 float 32bit DOUBLE : 类型 double 64bit
与CSize类似的类 : CRect
typedef struct tagRECT { LONG left; LONG top; LONG right; LONG bottom; } RECT, *PRECT, *LPRECT;
与CSize类似的类 : CRect
class CRect : public tagRECT {public: CRect(); CRect(int l, int t, int r, int b); CRect(const RECT& srcRect); CRect(LPCRECT lpSrcRect); CRect(POINT point, SIZE size); CRect(POINT topLeft, POINT bottomRight); 。。。 。。。
class CSize : public tagSIZE { 重载构造函数 public: CSize(); CSize(int initCX, int initCY); CSize(SIZE initSize); CSize(POINT initPt); 另外一个数据类 CSize(DWORD dwSize); 型 。。。 。。。
低16位为cx 高16位为cy
BOOL operator==(SIZE size) const; BOOL operator!=(SIZE size) const; 赋 值 void operator+=(SIZE size); void operator-=(SIZE size); 运 CSize operator+(SIZE size) const; 算 CSize operator-(SIZE size) const; CSize operator-() const; CPoint operator+(POINT point) const; CPoint operator-(POINT point) const; CRect operator+(const RECT* lpRect) const; CRect operator-(const RECT* lpRect) const;
关于CSize
typedef struct tagSIZE { LONG cx; LONG cy; } SIZE, *PSIZE, *LPSIZE;
类型定义
指向该类型的指针 1)typedef的作用是将这个struct定义成一个数据类型。 2)PSIZE 和 LPSIZE 均表示指向SIZE的指针,在16位系 统下有区别,在32位系统下没区别。 3)struct可以认为是成员都是public的类(class)。
4.
数据类型:(浮点型) 数据类型:(浮点型) :(浮点型
1. 2.
程序的可读性
好的程序体现在下面几个方面: 好的程序体现在下面几个方面:
正确性、可读性、健壮性、可维护性 正确性、可读性、健壮性、
VC++中关于提高可读性的几项基本要求: 中关于提高可读性的几项基本要求: 中关于提高可读性的几项基本要求
要遵循模块化缩进的原则。 要遵循模块化缩进的原则。 工程、 变量等等的名称一律用英文。 工程、类、变量等等的名称一律用英文。 变量起名要有意义,让人容易理解其含义。 变量起名要有意义,让人容易理解其含义。 采用英文,不要用汉语拼音。 采用英文,不要用汉语拼音。 不大容易理解的地方应及时加注释。 不大容易理解的地方应及时加注释。 变量写法遵循匈牙利记法。 变量写法遵循匈牙利记法。
typedef const RECT* LPCRECT;
// pointer to read/only RECT
关于LPCTSTR和CString类 和 关于 类
定义: 定义:typedef const CHAR *LPCTSTR; CString是管理字符串的类。 是管理字符串的类。 是管理字符串的类
MFC是由一系列类 是由一系列类(Class)构成的窗口 是由一系列类 构成的窗口 程序支撑体系。 程序支撑体系。
CObject CCmdTarget CWnd CDocument CWinApp
CFrameWnd
CDialog
CView
class CObject :
1) 一般诊断 AssertValid 2) 运行期识别 RuntimeClass 3) 串行化 Serialize 4) 动态创建 DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC
变量名的匈牙利记法 Hungarian notation
BOOL : bVariable int, INT : nVariable UINT : uVariable char, CHAR : chVariable BYTE : byVariable SHORT : sVariable WORD : wVariable LONG : lVariable DWORD : dwVariable FLOAT : fltVariable DOUBLE : dblVariable CHAR[] : szVariable
关于LPCTSTR和CSt) const; BOOL IsEmpty() const; 取值 void Empty(); TCHAR GetAt(int nIndex) const; TCHAR operator[](int nIndex) const; void SetAt(int nIndex, TCHAR ch); operator LPCTSTR() const;
class CCmdTarget : public CObject
1) 消息发送 BEGIN_MESSAGE_MAP(CMyView,Cview) ON_COMMAND(ID_FILE_OPEN,OnFileOpen) … … END_MESSAGE_MAP() 2) 等待光标 3) 支持自动化 IDispatch COM
MFC的基本数据类型
int 是特殊的数据类型,它等同于操作系统的 是特殊的数据类型, 位数。 位系统( 就是32位 位数。如32位系统(Win32)int就是 位。 位系统 ) 就是 2. 重新定义数据类型是为了可移植性。 重新定义数据类型是为了可移植性。 3. 数据类型:(整型) 数据类型:(整型) :(整型
比 较
CSize的用法
SIZE sizeBox1={20,40}; SIZE sizeBox2={60,30}; SIZE sizeBox3=sizeBox1+sizeBox2; CSize sizeBox(sizeBox1); 结果拷贝到 CSize sizeBigBox = sizeBox + sizeBox2;
class CDocument : public CCmdTarget
1) 文档的输入 输出。 文档的输入/输出 输出。 OpenDocument/SaveDocument 2) 数据的保存和更新; 数据的保存和更新; 3) View的维护。 的维护。 的维护
类型转换运算 CString::operator LPCTSTR() const 使用实例:CString str; { return m_pchData;(LPCTSTR) str; LPCTSTR lpsz = }
const CString& operator= (const CString& stringSrc); const CString& operator=(TCHAR ch); const CString& operator=(LPCSTR lpsz); const CString& operator=(LPCWSTR lpsz); const CString& operator=(const LPBYTE psz); const CString& operator+=(const CString& string); const CString& operator+=(TCHAR ch); const CString& operator+=(LPCTSTR lpsz); 。。。 。。。
相关文档
最新文档