《Visual C++ 6.0实例教程》电子教案 第7章

上传人:E**** 文档编号:89402575 上传时间:2019-05-24 格式:PPT 页数:70 大小:269KB
返回 下载 相关 举报
《Visual C++ 6.0实例教程》电子教案 第7章_第1页
第1页 / 共70页
《Visual C++ 6.0实例教程》电子教案 第7章_第2页
第2页 / 共70页
《Visual C++ 6.0实例教程》电子教案 第7章_第3页
第3页 / 共70页
《Visual C++ 6.0实例教程》电子教案 第7章_第4页
第4页 / 共70页
《Visual C++ 6.0实例教程》电子教案 第7章_第5页
第5页 / 共70页
点击查看更多>>
资源描述

《《Visual C++ 6.0实例教程》电子教案 第7章》由会员分享,可在线阅读,更多相关《《Visual C++ 6.0实例教程》电子教案 第7章(70页珍藏版)》请在金锄头文库上搜索。

1、第7章 MFC通用类,内容摘要: 1. MFC中数组类的使用方法 2. MFC中链表类的使用方法 3. MFC中字符串类CString的使用方法 4. MFC中日期和时间类的使用方法 5.MFC中CPoint类、CSize类和CRect类的使用方法,返回目录,7.1 数组类,学习目标 1.了解MFC中的数组类及其常用成员函数。 2.利用MFC中的数组类处理数据。,7.1,返回第7章,CByteArray: CDWordArray: CPtrArray: CUIntArray: CWordArray: CStringArray:,7.1,MFC的数组类,1int Add( ARG_TYPE ne

2、wElement ); throw( CMemoryException ); 2TYPE,7.1,MFC数组类的常用成员函数,例题(1-2),7.1,1.创建一个基于单文档的应用程序(Array) 2.编辑对话框资源 IDD_DIALOG_ADD IDC_STATIC Group Box Caption:设置添加操作 IDC_RADIO_SET Radio Button Caption:设置,Group:选中 IDC_RADIO_ADD Radio Button Caption:添加 IDC_RADIO_INSERT Radio Button Caption:插入 IDC_STATIC Sta

3、tic Text Caption:数组元素下标 IDC_EDIT_INDEX Edit Box IDC_STATIC Static Text Caption:设置值 IDC_EDIT_VALUE Edit Box IDOK Button Caption:确定 IDCANCEL Button Caption:取消,关联变量: IDC_RADIO_SET int m_nRidio IDC_EDIT_INDEX int m_nIndex IDC_EDIT_VALUE CString m_strValue,例题(2),7.1,(2) IDD_DIALOG_ADD IDC_STATIC Group Bo

4、x Caption:设置添加操作 IDC_RADIO_ALL Radio Button Caption:全部元素,Group:选中 IDC_RADIO_ELEMENT Radio Button Caption:指定元素 IDC_STATIC Static Text Caption:数组下标 IDC_EDIT_VALUE Edit Box IDOK Button Caption:确定 IDCANCEL Button Caption:取消,关联变量: IDC_RADIO_ALL int m_nRidio IDC_EDIT_VALUE int m_nIndex,例题(3),7.1,3为对话框IDD_

5、DIALOG_ADD添加响应函数,BOOL CDlgAdd:OnInitDialog() CDialog:OnInitDialog(); / TODO: Add extra initialization here (CButton*)GetDlgItem(IDC_RADIO_SET)-SetCheck(1); return TRUE; / return TRUE unless you set the focus to a control / EXCEPTION: OCX Property Pages should return FALSE ,void CDlgAdd:OnRadioSet()

6、/ TODO: Add your control notification handler code here GetDlgItem(IDC_EDIT_INDEX)-EnableWindow(true); ,例题(3),7.1,void CDlgAdd:OnRadioAdd() / TODO: Add your control notification handler code here GetDlgItem(IDC_EDIT_INDEX)-EnableWindow(false); ,void CDlgAdd:OnRadioInsert() / TODO: Add your control n

7、otification handler code here GetDlgItem(IDC_EDIT_INDEX)-EnableWindow(true); ,void CDlgAdd:OnOK() / TODO: Add extra validation here UpdateData(true); CDialog:OnOK(); ,例题(4),7.1,BOOL CDlgDelete:OnInitDialog() CDialog:OnInitDialog(); / TODO: Add extra initialization here (CButton*)GetDlgItem(IDC_RADIO

8、_ALL)-SetCheck(1); GetDlgItem(IDC_EDIT_INDEX)-EnableWindow(false); return TRUE; / return TRUE unless you set the focus to a control / EXCEPTION: OCX Property Pages should return FALSE ,void CDlgDelete:OnRadioElement() / TODO: Add your control notification handler code here GetDlgItem(IDC_EDIT_INDEX)

9、-EnableWindow(true); ,4为对话框IDD_DIALOG_DELETE添加响应函数,例题(4),7.1,void CDlgDelete:OnRadioAll() / TODO: Add your control notification handler code here GetDlgItem(IDC_EDIT_INDEX)-EnableWindow(false); ,void CDlgDelete:OnOK() / TODO: Add extra validation here UpdateData(true); CDialog:OnOK(); ,例题(5),7.1,pro

10、tected: CStringArray m_strArray;,CArrayView:CArrayView() / TODO: add construction code here m_strArray.SetSize(5,5); m_strArray0 = “111111111111“; m_strArray2 = “333333333333“; m_strArray4 = “555555555555“; ,5调用对话框并处理数组,(1)在视类中添加数组对象并初始化,例题(5),7.1,(2)编辑菜单资源 在菜单“编辑”下添加两个菜单项如下: ID号 Caption ID_EDIT_ADD

11、 设置添加 ID_EDIT_DELETE 删除,(3)添加ID_EDIT_ADD菜单项的消息响应函数,例题(5),7.1,void CArrayView:OnEditAdd() CDlgAdd dlg; dlg.m_nIndex = 0; dlg.m_strValue = “Default“; dlg.m_nRadio = 0; int result = dlg.DoModal(); if (result = IDOK) if (dlg.m_nRadio = 0) m_strArray.SetAtGrow(dlg.m_nIndex, dlg.m_strValue); else if (dlg.

12、m_nRadio = 1) m_strArray.Add(dlg.m_strValue); else m_strArray.InsertAt(dlg.m_nIndex, dlg.m_strValue, 1); Invalidate(); ,例题(5),7.1,void CArrayView:OnEditDelete() CDlgDelete dlg; dlg.m_nRadio= 0; dlg.m_nIndex= 0; int result = dlg.DoModal(); if (result = IDOK) if (dlg.m_nRadio=0) m_strArray.RemoveAll()

13、; else if(m_strArray.GetUpperBound() dlg.m_nIndex) AfxMessageBox(“The index is large than array upper bound!“); else m_strArray.RemoveAt(dlg.m_nIndex); Invalidate(); ,(4)添加ID_EDIT_DELETE菜单项的消息响应函数,例题(5),7.1,void CArrayView:OnDraw(CDC* pDC) CArrayDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); TEXTMET

14、RIC textMetric; pDC-GetTextMetrics( ,(5)重载视类的OnDraw()函数,7.2 链表类,学习目标 1.了解MFC中的链表类及其常用成员函数。 2.利用MFC中的链表类处理数据。,7.2,返回第7章,模板类 Clist CTypedPtrList 非模板类 CObList CPtrList CStringList,7.2,MFC的链表类,1CList( int nBlockSize = 10 ); 2TYPE GetHead( ) const; 3TYPE GetTail() const; 4RemoveHead() 5RemoveTail() 6原型1:

15、POSITION AddHead( ARG_TYPE newElement ); 原型2:void AddHead( CList* pNewList ); 7原型1:POSITION AddTail( ARG_TYPE newElement ); 原型2:void AddTail( CList* pNewList ); 8RemoveAll() 9POSITION GetHeadPosition( ) const; 10POSITION GetTailPosition( ) const; 11TYPE GetNext( POSITION,7.2,MFC链表类的常用成员函数以Clist为例,15void RemoveAt( POSITION position ); 16POSITION InsertBefore( POSITION position, ARG_TYPE newElement ); 17POSITION InsertAfter(

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号