MFC应用程序设计中的常用控件.doc

上传人:豆**** 文档编号:23973833 上传时间:2022-07-03 格式:DOC 页数:20 大小:273.50KB
返回 下载 相关 举报
MFC应用程序设计中的常用控件.doc_第1页
第1页 / 共20页
MFC应用程序设计中的常用控件.doc_第2页
第2页 / 共20页
点击查看更多>>
资源描述

《MFC应用程序设计中的常用控件.doc》由会员分享,可在线阅读,更多相关《MFC应用程序设计中的常用控件.doc(20页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateMFC应用程序设计中的常用控件MFC应用程序设计中的常用控件安康学院电子与信息工程学院实验报告课程名称VC+高级编程实验名称MFC应用程序设计中的常用控件(一)日期2018.5.29成绩姓名杨 旋学号2015024027班级15级计本1班一、实验目的:掌握利用MFC进行Windows应用程序设计时,常用控件的基本方法。二、实验题目内容及要求:1. 编写一个用于进行成绩

2、计算的程序。具体要求如下:界面中显示五个裁判所给出的等级制成绩(每个裁判利用一组单选按钮进行打分,成绩分为“优秀”、“良好”、“中等”、“及格”、“不及格”的档次),单击界面中的“计算”按钮之后,计算出百分制的平均成绩显示在界面中的一个文本框中,在计算时,每个档次的成绩对应的百分制成绩为:“优秀”95分“良好”85分“中等”75分“及格”65分“不及格”45分要求程序的运行界面自主设计,在完成上述基本功能前提下,可以进一步进行功能扩展。代码-#include stdafx.h#include MFCApplication4.h#include MFCApplication4Dlg.h#incl

3、ude afxdialogex.h#ifdef _DEBUG#define new DEBUG_NEW#endifclass CAboutDlg : public CDialogExpublic:CAboutDlg();#ifdef AFX_DESIGN_TIMEenum IDD = IDD_ABOUTBOX ;#endifprotected:virtual void DoDataExchange(CDataExchange* pDX); protected:DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialogEx(IDD_ABOUTBOX

4、)void CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)END_MESSAGE_MAP()/ CMFCApplication4Dlg 对话框CMFCApplication4Dlg:CMFCApplication4Dlg(CWnd* pParent /*=NULL*/): CDialogEx(IDD_MFCAPPLICATION4_DIALOG, pParent), m_po1(0), m_po2(0), m_po3

5、(0), m_po4(0), m_po5(0), m_result(0)m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CMFCApplication4Dlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);DDX_Radio(pDX, IDC_RADIO1, m_po1);DDX_Radio(pDX, IDC_RADIO6, m_po2);DDX_Radio(pDX, IDC_RADIO11, m_po3);DDX_Radio(pDX, IDC_RADIO16

6、, m_po4);DDX_Radio(pDX, IDC_RADIO21, m_po5);DDX_Text(pDX, IDC_EDIT1, m_result);BEGIN_MESSAGE_MAP(CMFCApplication4Dlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_RADIO1, &CMFCApplication4Dlg:OnBnClickedRadio1)ON_BN_CLICKED(IDC_RADIO6, &CMFCApplication4Dlg:OnBnClic

7、kedRadio6)ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication4Dlg:OnBnClickedButton1)ON_EN_CHANGE(IDC_EDIT1, &CMFCApplication4Dlg:OnEnChangeEdit1)END_MESSAGE_MAP()/ CMFCApplication4Dlg 消息处理程序BOOL CMFCApplication4Dlg:OnInitDialog()CDialogEx:OnInitDialog();ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(

8、IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);SetIcon(m_hIcon, TRUE);SetIcon(m_hIcon, FALSE);return TRUE; void CMFCApplication4Dlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialo

9、gEx:OnSysCommand(nID, lParam);void CMFCApplication4Dlg:OnPaint()if (IsIconic()CPaintDC dc(this); SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc(), 0);int cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width()

10、 - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;dc.DrawIcon(x, y, m_hIcon);elseCDialogEx:OnPaint();HCURSOR CMFCApplication4Dlg:OnQueryDragIcon()return static_cast(m_hIcon);int x1,x2,x3,x4,x5;void CMFCApplication4Dlg:OnBnClickedRadio1()switch (m_po1)case 0:x1 = 95;break;case 1:x1 = 85;bre

11、ak;case 2:x1 = 75;break;case 3:x1 = 65;break;case 4:x1 = 45;break;void CMFCApplication4Dlg:OnBnClickedRadio6()switch (m_po2)case 0:x2 = 95;break;case 1:x2 = 85;break;case 2:x2 = 75;break;case 3:x2 = 65;break;case 4:x2 = 45;break;void CMFCApplication4Dlg:OnBnClickedButton1()UpdateData(TRUE);switch (m

12、_po1)case 0:x1 = 95;break;case 1:x1 = 85;break;case 2:x1 = 75;break;case 3:x1 = 65;break;case 4:x1 = 45;break;switch (m_po2)case 0:x2 = 95;break;case 1:x2 = 85;break;case 2:x2 = 75;break;case 3:x2 = 65;break;case 4:x2 = 45;break;switch (m_po3)case 0:x3 = 95;break;case 1:x3= 85;break;case 2:x3 = 75;b

13、reak;case 3:x3 = 65;break;case 4:x3 = 45;break;switch (m_po4)case 0:x4 = 95;break;case 1:x4 = 85;break;case 2:x4 = 75;break;case 3:x4 = 65;break;case 4:x4 = 45;break;switch (m_po5)case 0:x5 = 95;break;case 1:x5 = 85;break;case 2:x5 = 75;break;case 3:x5 = 65;break;case 4:x5 = 45;break;m_result = (x1

14、+ x2+x3+x4+x5)/5;UpdateData(FALSE);void CMFCApplication4Dlg:OnEnChangeEdit1()运行结果:2.创建一个简单的调色板程序,程序界面中可以利用滚动条进行红、绿、蓝三种颜色分量值的调整,也可以直接在文本框中输入红、绿、蓝三种颜色分量值,在颜色分量值调整变化的同时,变化的颜色效果通过一个圆形色块进行现式。在完成上述基本功能前提下,可以进一步进行功能扩展。代码:#include stdafx.h#include MFCApplication5.h#include MFCApplication5Dlg.h#include afxdi

15、alogex.h#ifdef _DEBUG#define new DEBUG_NEW#endifclass CAboutDlg : public CDialogExpublic:CAboutDlg();#ifdef AFX_DESIGN_TIMEenum IDD = IDD_ABOUTBOX ;#endifprotected:virtual void DoDataExchange(CDataExchange* pDX); protected:DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialogEx(IDD_ABOUTBOX)void CAb

16、outDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)END_MESSAGE_MAP()CMFCApplication5Dlg:CMFCApplication5Dlg(CWnd* pParent : CDialogEx(IDD_MFCAPPLICATION5_DIALOG, pParent), m_red(0), m_yellow(0), m_blue(0)m_hIcon = AfxGetApp()-LoadIcon(IDR_MA

17、INFRAME);void CMFCApplication5Dlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);DDX_Control(pDX, IDC_SCROLLBAR3, m_scr1);DDX_Control(pDX, IDC_SCROLLBAR1, m_scr2);DDX_Control(pDX, IDC_SCROLLBAR2, m_scr3);DDX_Text(pDX, IDC_EDIT1, m_red);DDX_Text(pDX, IDC_EDIT2, m_yellow);DDX_Text(pDX

18、, IDC_EDIT3, m_blue);BEGIN_MESSAGE_MAP(CMFCApplication5Dlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_WM_VSCROLL()ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication5Dlg:OnBnClickedButton1)ON_BN_CLICKED(IDC_BUTTON2, &CMFCApplication5Dlg:OnBnClickedButton2)END_MESSAGE_MAP()BOOL CMFCApp

19、lication5Dlg:OnInitDialog()CDialogEx:OnInitDialog();ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);SetIcon(m_hIcon, TRUE);SetIcon(m_hIcon, FALSE);m_scr1.SetScrollRange(0, 255);m_scr1.SetScrollPos(0

20、);m_scr2.SetScrollRange(0, 255);m_scr2.SetScrollPos(0);m_scr3.SetScrollRange(0, 255);m_scr3.SetScrollPos(0);return TRUE; /void CMFCApplication5Dlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialogEx:OnSysCommand(nID, lParam);void

21、CMFCApplication5Dlg:OnPaint()if (IsIconic()CPaintDC dc(this); SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc(), 0);int cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.He

22、ight() - cyIcon + 1) / 2;/ 绘制图标dc.DrawIcon(x, y, m_hIcon);elseCDialogEx:OnPaint();HCURSOR CMFCApplication5Dlg:OnQueryDragIcon()return static_cast(m_hIcon);int x1, x2, x3;void CMFCApplication5Dlg:OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)int iNowPos;if (pScrollBar = &m_scr1)switch (nS

23、BCode)case SB_THUMBTRACK:m_scr1.SetScrollPos(nPos);x1 = m_scr1.GetScrollPos();case SB_LINEDOWN:iNowPos = m_scr1.GetScrollPos();iNowPos = iNowPos + 1;if (iNowPos 255)iNowPos = 255;m_scr1.SetScrollPos(iNowPos);x1 = m_scr1.GetScrollPos();break;case SB_LINEUP:iNowPos = m_scr1.GetScrollPos();iNowPos = iN

24、owPos - 1;if (iNowPos 255)iNowPos = 255;m_scr1.SetScrollPos(iNowPos);x1 = m_scr1.GetScrollPos();break;case SB_PAGEUP:iNowPos = m_scr1.GetScrollPos();iNowPos = iNowPos - 3;if (iNowPos 255)iNowPos = 255;m_scr2.SetScrollPos(iNowPos);x2 = m_scr2.GetScrollPos();break;case SB_LINEUP:iNowPos = m_scr2.GetSc

25、rollPos();iNowPos = iNowPos - 1;if (iNowPos 255)iNowPos = 255;m_scr2.SetScrollPos(iNowPos);x2 = m_scr2.GetScrollPos();break;case SB_PAGEUP:iNowPos = m_scr1.GetScrollPos();iNowPos = iNowPos - 3;if (iNowPos 255)iNowPos = 255;m_scr3.SetScrollPos(iNowPos);x3 = m_scr3.GetScrollPos();break;case SB_LINEUP:

26、iNowPos = m_scr3.GetScrollPos();iNowPos = iNowPos - 1;if (iNowPos 255)iNowPos = 255;m_scr3.SetScrollPos(iNowPos);x3 = m_scr3.GetScrollPos();break;case SB_PAGEUP:iNowPos = m_scr3.GetScrollPos();iNowPos = iNowPos - 3;if (iNowPos LoadIcon(IDR_MAINFRAME);void CMFCApplication6Dlg:DoDataExchange(CDataExch

27、ange* pDX)CDialogEx:DoDataExchange(pDX);DDX_Radio(pDX, IDC_RADIO1, m_PenStyle);DDX_Radio(pDX, IDC_RADIO5, m_BrushStyle);DDX_Control(pDX, IDC_COMBO1, m_PenColor);DDX_Control(pDX, IDC_COMBO2, m_BrushColor);DDX_Control(pDX, IDC_LIST1, m_List);BEGIN_MESSAGE_MAP(CMFCApplication6Dlg, CDialogEx)ON_WM_SYSCO

28、MMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_RADIO1, &CMFCApplication6Dlg:OnBnClickedRadio1)ON_BN_CLICKED(IDC_RADIO5, &CMFCApplication6Dlg:OnBnClickedRadio5)ON_CBN_SELCHANGE(IDC_COMBO1, &CMFCApplication6Dlg:OnCbnSelchangeCombo1)ON_CBN_SELCHANGE(IDC_COMBO2, &CMFCApplication6Dlg:OnCbnSel

29、changeCombo2)ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication6Dlg:OnBnClickedButton1)ON_LBN_SELCHANGE(IDC_LIST1, &CMFCApplication6Dlg:OnLbnSelchangeList1)END_MESSAGE_MAP()BOOL CMFCApplication6Dlg:OnInitDialog()CDialogEx:OnInitDialog();ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);SetIcon(m_hIcon, T

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

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁