欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    MFC应用程序设计中的常用控件(共15页).doc

    • 资源ID:16270446       资源大小:159KB        全文页数:15页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    MFC应用程序设计中的常用控件(共15页).doc

    精选优质文档-倾情为你奉上安康学院电子与信息工程学院实验报告课程名称VC+高级编程实验名称MFC应用程序设计中的常用控件(一)日期2018.5.29成绩姓名杨 旋学号班级15级计本1班一、实验目的:掌握利用MFC进行Windows应用程序设计时,常用控件的基本方法。二、实验题目内容及要求:1. 编写一个用于进行成绩计算的程序。具体要求如下:界面中显示五个裁判所给出的等级制成绩(每个裁判利用一组单选按钮进行打分,成绩分为“优秀”、“良好”、“中等”、“及格”、“不及格”的档次),单击界面中的“计算”按钮之后,计算出百分制的平均成绩显示在界面中的一个文本框中,在计算时,每个档次的成绩对应的百分制成绩为:“优秀”95分“良好”85分“中等”75分“及格”65分“不及格”45分要求程序的运行界面自主设计,在完成上述基本功能前提下,可以进一步进行功能扩展。代码专心-专注-专业#include "stdafx.h"#include "MFCApplication4.h"#include "MFCApplication4Dlg.h"#include "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)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(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, 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:OnBnClickedRadio6)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(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)BOOL bNameValid;CString strAboutMenu;bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);ASSERT(bNameValid);if (!strAboutMenu.IsEmpty()pSysMenu->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();elseCDialogEx:OnSysCommand(nID, lParam);void CMFCApplication4Dlg:OnPaint()if (IsIconic()CPaintDC dc(this); SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(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.Height() - cyIcon + 1) / 2;dc.DrawIcon(x, y, m_hIcon);elseCDialogEx:OnPaint();HCURSOR CMFCApplication4Dlg:OnQueryDragIcon()return static_cast<HCURSOR>(m_hIcon);int x1,x2,x3,x4,x5;void CMFCApplication4Dlg:OnBnClickedRadio1()switch (m_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;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_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;break;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 + x2+x3+x4+x5)/5;UpdateData(FALSE);void CMFCApplication4Dlg:OnEnChangeEdit1()运行结果:2.创建一个简单的调色板程序,程序界面中可以利用滚动条进行红、绿、蓝三种颜色分量值的调整,也可以直接在文本框中输入红、绿、蓝三种颜色分量值,在颜色分量值调整变化的同时,变化的颜色效果通过一个圆形色块进行现式。在完成上述基本功能前提下,可以进一步进行功能扩展。代码:#include "stdafx.h"#include "MFCApplication5.h"#include "MFCApplication5Dlg.h"#include "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)void CAboutDlg: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_MAINFRAME);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, 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 CMFCApplication5Dlg:OnInitDialog()CDialogEx:OnInitDialog();ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)BOOL bNameValid;CString strAboutMenu;bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);ASSERT(bNameValid);if (!strAboutMenu.IsEmpty()pSysMenu->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);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 CMFCApplication5Dlg:OnPaint()if (IsIconic()CPaintDC dc(this); SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(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.Height() - cyIcon + 1) / 2;/ 绘制图标dc.DrawIcon(x, y, m_hIcon);elseCDialogEx:OnPaint();HCURSOR CMFCApplication5Dlg:OnQueryDragIcon()return static_cast<HCURSOR>(m_hIcon);int x1, x2, x3;void CMFCApplication5Dlg:OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)int iNowPos;if (pScrollBar = &m_scr1)switch (nSBCode)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 = iNowPos - 1;if (iNowPos < 0)iNowPos = 0;m_scr1.SetScrollPos(iNowPos);x1 = m_scr1.GetScrollPos();break;case SB_PAGEDOWN:iNowPos = m_scr1.GetScrollPos();iNowPos = iNowPos + 3;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 < 0)iNowPos = 0;m_scr1.SetScrollPos(iNowPos);x1 = m_scr1.GetScrollPos();break; else if (pScrollBar = &m_scr2)switch (nSBCode)case SB_THUMBTRACK:m_scr2.SetScrollPos(nPos);x2 = m_scr2.GetScrollPos();case SB_LINEDOWN:iNowPos = m_scr2.GetScrollPos();iNowPos = iNowPos + 1;if (iNowPos > 255)iNowPos = 255;m_scr2.SetScrollPos(iNowPos);x2 = m_scr2.GetScrollPos();break;case SB_LINEUP:iNowPos = m_scr2.GetScrollPos();iNowPos = iNowPos - 1;if (iNowPos < 0)iNowPos = 0;m_scr2.SetScrollPos(iNowPos);x2 = m_scr2.GetScrollPos();break;case SB_PAGEDOWN:iNowPos = m_scr2.GetScrollPos();iNowPos = iNowPos + 3;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 < 0)iNowPos = 0;m_scr2.SetScrollPos(iNowPos);x2 = m_scr2.GetScrollPos();break;else if (pScrollBar = &m_scr3)switch (nSBCode)case SB_THUMBTRACK:m_scr3.SetScrollPos(nPos);x3 = m_scr3.GetScrollPos();case SB_LINEDOWN:iNowPos = m_scr3.GetScrollPos();iNowPos = iNowPos + 1;if (iNowPos > 255)iNowPos = 255;m_scr3.SetScrollPos(iNowPos);x3 = m_scr3.GetScrollPos();break;case SB_LINEUP:iNowPos = m_scr3.GetScrollPos();iNowPos = iNowPos - 1;if (iNowPos < 0)iNowPos = 0;m_scr3.SetScrollPos(iNowPos);x3 = m_scr3.GetScrollPos();break;case SB_PAGEDOWN:iNowPos = m_scr3.GetScrollPos();iNowPos = iNowPos + 3;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 < 0)iNowPos = 0;m_scr3.SetScrollPos(iNowPos);x3 = m_scr3.GetScrollPos();break;CDialogEx:OnVScroll(nSBCode, nPos, pScrollBar);void CMFCApplication5Dlg:OnBnClickedButton1()/ TODO: 在此添加控件通知处理程序代码CClientDC hDC(this);CPen *penold, pennew;CBrush *brushold, brushnew, brushback;CRect rectclient;GetClientRect(&rectclient); CRectrectdraw(rectclient.right - 170, 10, rectclient.right - 10, 170);brushback.CreateSolidBrush(RGB(x1, x2, x3);brushold = hDC.SelectObject(&brushback);penold = hDC.SelectObject(&pennew);hDC.SelectObject(&brushnew);hDC.Ellipse(rectdraw);hDC.SelectObject(penold);hDC.SelectObject(brushold);void CMFCApplication5Dlg:OnBnClickedButton2()/ TODO: 在此添加控件通知处理程序代码UpdateData(TRUE);CClientDC hDC(this);CPen *penold, pennew;CBrush *brushold, brushnew, brushback;CRect rectclient;GetClientRect(&rectclient);CRectrectdraw(rectclient.right - 170, 10, rectclient.right - 10, 170);brushback.CreateSolidBrush(RGB(m_red, m_yellow, m_blue);brushold = hDC.SelectObject(&brushback);penold = hDC.SelectObject(&pennew);hDC.SelectObject(&brushnew);hDC.Ellipse(rectdraw);hDC.SelectObject(penold);hDC.SelectObject(brushold);UpdateData(FALSE);运行结果:3.完成教材第255页习题9-17。代码#include "stdafx.h"#include "MFCApplication6.h"#include "MFCApplication6Dlg.h"#include "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)void CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)END_MESSAGE_MAP()CMFCApplication6Dlg:CMFCApplication6Dlg(CWnd* pParent CDialogEx(IDD_MFCAPPLICATION6_DIALOG, pParent), m_PenStyle(0), m_BrushStyle(0)m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);void CMFCApplication6Dlg:DoDataExchange(CDataExchange* 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_SYSCOMMAND()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:OnCbnSelchangeCombo2)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 < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)BOOL bNameValid;CString strAboutMenu;bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);ASSERT(bNameValid);if (!strAboutMenu.IsEmpty()pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);SetIcon(m_hIcon, TRUE);SetIcon(m_hIcon, FALSE);m_PenColor.AddString(L"Red");m_PenColor.AddString(L"Yellow");m_PenColor.AddString(L"Blue");m_PenColor.SelectString(-1,L"RED");m_BrushColor.AddString(L"Red");m_BrushColor.AddString(L"Yellow");m_BrushColor.AddString(L"Blu

    注意事项

    本文(MFC应用程序设计中的常用控件(共15页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

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

    收起
    展开