vc++期末复习_第1页
vc++期末复习_第2页
vc++期末复习_第3页
vc++期末复习_第4页
vc++期末复习_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1 MFC程序的基本操作流程1利用ClassWizard为控件添加成员变量时,请写出所有的代码变化。(必考)将控件定义为CMy0901Dlg类的成员: CStringm_yyy;在CMy0901Dlg:DoDataExchange()中,自动维护DDX_Control() DDX_Text(pDX, IDC_EDIT1, m_yyy);在CMy0904Dlg:CMy0904Dlg()中初始化 m_yyy = _T("");2 利用ClassWizard为控件添加映射函数时,请写出所有的代码变化。(必考)在CMy0901Dlg类定义中,说明了以上函数:afx_msg void

2、 OnButton1();在CMy0901Dlg类实现中,创建控件CLICKED消息对应的函数: void CMy0901Dlg:OnButton1() 在CMy0901Dlg类实现中,在BEGIN_MESSAGE_MAP宏中,关联事件和函数:ON_BN_CLICKED(IDC_BUTTON1, OnButton1)3 常用事件的含义(抽五个)视图事件:WM_SIZE:改变窗口大小 WM_DESTROY:销毁窗口 WM_TIMER: WM_CREATE:创建窗口对话框 WM_INITDIALOG对话框上所有的子控件创建完成之后选择发送的消息 WM_PAINT:绘制窗口 WM_CLOSE:按钮

3、BN_CLICKED 单击了窗口菜单列表框:LBN_SELCHANGE列表框某项的选择被取消 LBN_DBLCLK双击了列表框的某一项编辑框EN_CHANGE 编辑框中的文本被更新4 常用的虚函数的作用(都考)文档类:OnOpenDocument OnSaveDocument Serialize 视图类:OnUpdate OnDraw应用程序类InitInstance 框架类PreCreateWindow OnCreateClient5 框架类的理解利用MFC的APPWizard创建一个应用工程。简述MFC自动生成了哪些类及其功能2 窗口程序中基本元素的操作技术(读程序、补充程序)快捷菜单、动

4、态菜单动态菜单(两个函数流程意思)/! / 获得程序菜单指针CMenu* pMenu = GetMenu(); / 获得第二个子菜单的指针 CMenu* pMenu1 = pMenu->GetSubMenu(1); / 添加一个分隔线pMenu1->AppendMenu(MF_SEPARATOR); / 在子菜单中增加一菜单项pMenu1->AppendMenu(MF_STRING,ID_NEW_MENUITEM+0,"新项1");/?AppendMenu ? ID_NEW_MENUITEM +0,"新项1" ?/ 避免系统将“无代码的

5、菜单项”自动置虚m_bAutoMenuEnable = FALSE; / 自动更新菜单状态开关 / 修改菜单后,应重画菜单 DrawMenuBar();return 0;/!BOOL CMainFrame:OnCommand(WPARAM wParam, LPARAM lParam) WORD nID =LOWORD(wParam); /?WORD nCode=HIWORD(wParam); /? if(nID=ID_NEW_MENUITEM+0) MessageBox("你选中了新的菜单项1");return CFrameWnd:OnCommand(wParam, lPa

6、ram);BOOL CMainFrame:PreCreateWindow(CREATESTRUCT& cs)if( !CFrameWnd:PreCreateWindow(cs) )return FALSE;/ TODO: Modify the Window class or styles here by modifying/ the CREATESTRUCT csreturn TRUE;快捷菜单(讲清所标程序流程)/!void CMainFrame:OnContextMenu(CWnd* pWnd, CPoint point) CMenu* pMenu=new CMenu; /? pM

7、enu->LoadMenu(IDR_MENU1); /? CMenu* pMenu1; pMenu1 = pMenu->GetSubMenu(0); /? pMenu1->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x,point.y,this); /?void CMainFrame:OnMenu3() AfxMessageBox("OnMenu3()");状态栏(cmainframe oncreate ctestview onmousemove)与视图(?)cmainframe oncreate

8、:int CMainFrame:OnCreate(LPCREATESTRUCT lpCreateStruct)if (CFrameWnd:OnCreate(lpCreateStruct) = -1)return -1;if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) |!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)TRACE0

9、("Failed to create toolbarn");return -1; / fail to createif (!m_wndStatusBar.Create(this) |!m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)TRACE0("Failed to create status barn");return -1; / fail to create/ TODO: Delete these three lines if you don't

10、want the toolbar to/ be dockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);return 0;CTestview OnMouseMove:void CTestView:OnMouseMove(UINT nFlags, CPoint point) CString s; s.Format("X=%d, Y=%d",point.x, point.y); / 获得窗口框架的指针 CM

11、ainFrame* pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd; pFrame->m_wndStatusBar.SetPaneText(1,s); CView:OnMouseMove(nFlags, point);时钟与作图(读程序或补程序)图形加刷子(?)void CTestView:OnSize(UINT nType, int cx, int cy) CView:OnSize(nType, cx, cy);/ TODO: Add your message handler code herevoid CTestView:OnGameSt

12、art() SetTimer(1,100,NULL);void CTestView:OnTimer(UINT nIDEvent) m_Box.left +=dx; m_Box.right+=dx; m_Box.top +=dy; m_Box.bottom+=dy; Invalidate();CView:OnTimer(nIDEvent);void CTestView:OnDraw(CDC* pDC)CTestDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data herepDC->

13、;Rectangle(&m_Box); /?void CTestView:OnGameStop() KillTimer(1);private:RECT m_Box;int dx,dy;位图(MyBitmaps 某个成员变量(dcimage)的信息)数据库(连接字符串。关闭链接显示数据库)位图:myBitmaps:myBitmaps(char fname,CDC *pDC)this->pDC=pDC;HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,fname,IMAGE_BITMAP,0,0,LR_LOADFROMFILE); CBitmap obj

14、Bitmap; /操作位图的类objBitmap.Attach(hBitmap);objBitmap.GetBitmap(&bm); /读取位图结构(长宽字节) /建立图像设备上下文dcImage.CreateCompatibleDC(pDC); dcImage.SelectObject(&objBitmap); myBitmaps:myBitmaps()DeleteDC(dcImage);void myBitmaps:Draw(CDC *pDC)pDC->BitBlt(100,100, bm.bmWidth,bm.bmHeight,&dcImage, 0, 0,

15、SRCCOPY); class myBitmaps CDC dcImage;BITMAP bm;CDC *pDC;public:void Draw(CDC *pDC);myBitmaps(char fname,CDC *pDC);virtual myBitmaps();数据库:void CTestView:OnDbconnect() /!:CoInitialize(NULL); / 初始化COM环境m_Cn.CreateInstance("ADODB.Connection");m_Cn->Open("Provider=Microsoft.Jet.OLEDB.

16、4.0;Data Source=canyin.mdb","","",adModeUnknown);void CTestView:OnDbdisconnct() /!m_Cn->Close(); void CTestView:OnDbdisplay() /!_RecordsetPtr m_pRecordset;m_pRecordset.CreateInstance("ADODB.Recordset");/m_pRecordset->Open("cai",m_Cn.GetInterfacePtr(

17、), adOpenDynamic,adLockOptimistic, adCmdTable);CString scmd="Select * from cai where Price>20"m_pRecordset->Open(_variant_t)scmd, m_Cn.GetInterfacePtr(), adOpenDynamic,adLockOptimistic, adCmdText);while(!m_pRecordset->adoEOF)/?/查询当前记录的各种字段的值/!int ID = (int)m_pRecordset->GetColl

18、ect("ID").lVal; /?CString Name =(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Name"); /?float Price = m_pRecordset->GetCollect("Price").fltVal; /?m_ID=ID; m_Name=Name; /?UpdateData();/!m_pRecordset->MoveNext(); /当前记录后移/?void CTestView:OnDbchange() CString Sql;/Sq

19、l="Update cai set Price=Price+1 where ID=2"/Sql="Delete from cai where ID=2"Sql="Insert into cai(ID,Name,Price) Values(11,'ccc',90)"/!m_Cn->Execute(_bstr_t)Sql,NULL,adCmdText);一档多视(A1,A2)(CFormView CListView)void CA2View:OnUpdate(CView* pSender, LPARAM lHint,

20、 CObject* pHint) m_List1.ResetContent();CA2Doc* pDoc = (CA2Doc*)GetDocument();for(int i=0; i<pDoc->GetCount(); i+) CPoint *p=pDoc->GetPoint(i);! CString s; s.Format("%d,%d",p->x,p->y); ! m_List1.AddString(s);类的序列化串行化wqline/!五个地方填空/支持串行化,需要使用宏定义class wqLine :public CObject /!

21、DECLARE_SERIAL(wqLine) /!POINT sp,ep;public:wqLine();wqLine(POINT sp,POINT ep);virtual wqLine();void Draw(CDC *pDC);virtual void Serialize(CArchive& ar); /!;CTestDoc serializationvoid CTestDoc:Serialize(CArchive& ar)if (ar.IsStoring()if(pLine!=NULL)pLine->Serialize(ar);elsepLine=new wqLin

22、e();pLine->Serialize(ar);public:wqLine * pLine;virtual CTestDoc();控件:CListCtrl CTreeView(树形控件给层次结构写代码) void CTestDlg:OnButton1() HTREEITEM root=m_Tree.InsertItem("Parent",TVI_ROOT,TVI_LAST) ;m_Tree.InsertItem("son1",root,TVI_LAST) ;HTREEITEM son2=m_Tree.InsertItem("son2&q

23、uot;,root,TVI_LAST) ;m_Tree.InsertItem("son3",root,TVI_LAST) ;m_Tree.InsertItem("sonson1",son2,TVI_LAST) ;m_Tree.InsertItem("sonson2",son2,TVI_LAST) ;m_Tree.InsertItem("sonson3",son2,TVI_LAST) ;m_Tree.Expand(root,TVE_EXPAND);m_Tree.Expand(son2,TVE_EXPAND);void

24、 CTestDlg:OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;HTREEITEM p=m_Tree.GetSelectedItem();HTREEITEM parent=m_Tree.GetParentItem(p); CString ptext = m_Tree.GetItemText(p); CString parenttext = m_Tree.GetItemText(parent); AfxMessageBox(ptext + &q

25、uot;n" + parenttext);*pResult = 0;3 基本编程能力显示对话框(考)列表框、组合框的操作(2选1)列表框:void CTestDlg:OnButtonappend() static int n=0;n+;CString s;s.Format("aaaaa %d", n) ;m_lstName.AddString (s);void CTestDlg:OnSelchangeListname() int index=m_lstName.GetCurSel() ;CString s;s.Format("index=%d"

26、, index) ; CString name;m_lstName.GetText(index, name); m_Name=s+": "+name;UpdateData(FALSE);组合框(droplist):void CTestDialog:OnButtonFill() CString ss7="星期一","星期二","星期三", "星期四","星期五","星期六","星期日" m_Combo1.ResetContent(); f

27、or(int i=0; i<7; i+) m_Combo1.AddString(ssi); m_Combo1.SetCurSel(0); / 必要 for( i=0; i<7; i+) m_Combo3.AddString(ssi);void CTestDialog:OnButtonClear() int n=m_Combo1.GetCount(); for(int i=n-1; i>=0; i-) m_Combo1.DeleteString(i); m_Combo1.SetCurSel(-1);void CTestDialog:OnSelchangeCombo1() int

28、 index=m_Combo1.GetCurSel(); CString s; m_Combo1.GetLBText(index, s); AfxMessageBox(s);void CTestDialog:OnEditchangeCombo3() CString s;m_Combo3.GetWindowText(s);m_Combo3.AddString(s);void CTestDialog:OnButtonFill() CString ss7="星期一","星期二","星期三","星期四", "星期

29、五","星期六","星期日" for(int i=0; i<7; i+) m_Combo1.AddString(ssi); m_Combo1.SetCurSel(0); void CTestDialog:OnButtonAppend() CString s; m_Combo1.GetWindowText(s); if(m_Combo1.FindString(0,s)=CB_ERR) m_Combo1.AddString(s); 绘图程序(考)4 基本实践能力(试图条理清晰) 本学期你一定编写了一些窗口程序,或者经历了一些窗口程序的开发过程。请写出其中你认为最精彩的程序的设计方案。设计方案应包括:程序的流程,类的组成,类中的核心数据成员,核心函数。贪吃蛇游戏程序流程:在菜单栏点击按钮“游戏”,选择“开始”,出现游戏页面(矩形的游戏边界、方块体圆头的贪吃蛇和方形食物),点击方向按钮启动游戏蛇开始运动,四个方向键控制蛇的方向。当蛇头接触食物时食物消失,弹出“胜利”对话

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论