实验七-MFC-控件编程实验_第1页
实验七-MFC-控件编程实验_第2页
实验七-MFC-控件编程实验_第3页
实验七-MFC-控件编程实验_第4页
实验七-MFC-控件编程实验_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

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

文档简介

实验七实验七 MFCMFC 控件编程实验控件编程实验 一 实验目的 1 熟悉Visual C 6 0 开发环境 2 掌握MFC 环境下标准控件的使用方法 3 熟练掌握在Visual C 6 0 开发环境调试程序的方法 二 实验内容 创建如图所示的应用程序 在 形状 列表框中选择要绘制的图形 在 笔颜 色 下拉列表框中选择画笔的颜色 在 刷子颜色 下拉列表框中选择画刷的 颜色 在 线型 组框中选择画笔的线型 在 填充类型 中选择画刷填充类型 单 击 绘图 按钮 在 绘图设置 编辑框中显示选择的绘图设置选项 单击 退出 按钮退 出程序 三 程序代码 testDlg cpp implementation file include stdafx h include test h include testDlg h ifdef DEBUG define new DEBUG NEW undef THIS FILE static char THIS FILE FILE endif CAboutDlg dialog used for App About class CAboutDlg public CDialog public CAboutDlg Dialog Data AFX DATA CAboutDlg enum IDD IDD ABOUTBOX AFX DATA ClassWizard generated virtual function overrides AFX VIRTUAL CAboutDlg protected virtual void DoDataExchange CDataExchange pDX DDX DDV support AFX VIRTUAL Implementation protected AFX MSG CAboutDlg AFX MSG DECLARE MESSAGE MAP CAboutDlg CAboutDlg CDialog CAboutDlg IDD AFX DATA INIT CAboutDlg AFX DATA INIT void CAboutDlg DoDataExchange CDataExchange pDX CDialog DoDataExchange pDX AFX DATA MAP CAboutDlg AFX DATA MAP BEGIN MESSAGE MAP CAboutDlg CDialog AFX MSG MAP CAboutDlg No message handlers AFX MSG MAP END MESSAGE MAP CTestDlg dialog CTestDlg CTestDlg CWnd pParent NULL CDialog CTestDlg IDD pParent AFX DATA INIT CTestDlg m pen 1 m brush 1 m Output T AFX DATA INIT Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m hIcon AfxGetApp LoadIcon IDR MAINFRAME void CTestDlg DoDataExchange CDataExchange pDX CDialog DoDataExchange pDX AFX DATA MAP CTestDlg DDX Control pDX IDC LIST1 m list DDX Control pDX IDC COMBO2 m cb2 DDX Control pDX IDC COMBO1 m cb1 DDX Radio pDX IDC RADIO1 m pen DDX Radio pDX IDC RADIO5 m brush DDX Text pDX IDC OUTPUT m Output AFX DATA MAP BEGIN MESSAGE MAP CTestDlg CDialog AFX MSG MAP CTestDlg ON WM SYSCOMMAND ON WM PAINT ON WM QUERYDRAGICON ON EN CHANGE IDC OUTPUT OnChangeOutput ON BN CLICKED IDC BUTTON1 OnButton1 ON LBN SELCHANGE IDC LIST1 OnSelchangeList1 ON CBN SELCHANGE IDC COMBO1 OnSelchangeCombo1 ON CBN SELCHANGE IDC COMBO2 OnSelchangeCombo2 ON CBN EDITCHANGE IDC COMBO2 OnSelchangeCombo2 AFX MSG MAP END MESSAGE MAP CTestDlg message handlers BOOL CTestDlg OnInitDialog CDialog OnInitDialog Add About menu item to system menu IDM ABOUTBOX must be in the system command range ASSERT IDM ABOUTBOX ASSERT IDM ABOUTBOX AppendMenu MF SEPARATOR pSysMenu AppendMenu MF STRING IDM ABOUTBOX strAboutMenu Set the icon for this dialog The framework does this automatically when the application s main window is not a dialog SetIcon m hIcon TRUE Set big icon SetIcon m hIcon FALSE Set small icon TODO Add extra initialization here m list AddString Line m list AddString Circle m list AddString Rectangle m list AddString RoundRectangle m cb1 AddString Red m cb1 AddString Blue m cb1 AddString Black return TRUE return TRUE unless you set the focus to a control void CTestDlg OnSysCommand UINT nID LPARAM lParam if nID dlgAbout DoModal else CDialog OnSysCommand nID lParam If you add a minimize button to your dialog you will need the code below to draw the icon For MFC applications using the document view model this is automatically done for you by the framework void CTestDlg OnPaint if IsIconic CPaintDC dc this device context for painting SendMessage WM ICONERASEBKGND WPARAM dc GetSafeHdc 0 Center icon in client rectangle int cxIcon GetSystemMetrics SM CXICON int cyIcon GetSystemMetrics SM CYICON CRect rect GetClientRect int x rect Width cxIcon 1 2 int y rect Height cyIcon 1 2 Draw the icon dc DrawIcon x y m hIcon else CDialog OnPaint The system calls this to obtain the cursor to display while the user drags the minimized window HCURSOR CTestDlg OnQueryDragIcon return HCURSOR m hIcon void CTestDlg OnChangeOutput TODO If this is a RICHEDIT control the control will not send this notification unless you override the CDialog OnInitDialog function and call CRichEditCtrl SetEventMask with the ENM CHANGE flag ORed into the mask TODO Add your control notification handler code here CString msg1 CString msg2 CString msg3 void CTestDlg OnSelchangeList1 TODO Add your control notification handler code here m list GetText m list GetCurSel msg1 void CTestDlg OnSelchangeCombo1 TODO Add your control notification handler code here m cb1 GetLBText m cb1 GetCurSel msg2 void CTestDlg OnSelchangeCombo2 TODO Add your control notification handler code here m cb2 GetLBText m cb2 GetCurSel msg3 void CTestDlg OnButton1 TODO Add your control notification handler code here UpdateData TRUE DDX 界面控件的值传给内部变量 m Output 形状 m Output msg1 m Output 笔颜色 m Output msg2 m Output 刷子颜色 m Output msg3 m Output 线型 switch m pen case 0 m Output Solid break case 1 m Output Dash break case 2 m

温馨提示

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

最新文档

评论

0/150

提交评论