300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Visual C++——黄维通《 Visual C++面向对象与可视化程序设计》——例题9-5

Visual C++——黄维通《 Visual C++面向对象与可视化程序设计》——例题9-5

时间:2021-06-07 23:37:13

相关推荐

Visual C++——黄维通《 Visual C++面向对象与可视化程序设计》——例题9-5

问题描述

略。

解决方案

// 329621200_申屠志刚_可视化编程技术B_实验四Dlg.cpp : implementation file//#include "stdafx.h"#include "329621200_申屠志刚_可视化编程技术B_实验四.h"#include "329621200_申屠志刚_可视化编程技术B_实验四Dlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/// CAboutDlg dialog used for App Aboutclass 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// Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_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_MAPEND_MESSAGE_MAP()/// CMy329621200__B_Dlg dialogCMy329621200__B_Dlg::CMy329621200__B_Dlg(CWnd* pParent /*=NULL*/): CDialog(CMy329621200__B_Dlg::IDD, pParent){//{{AFX_DATA_INIT(CMy329621200__B_Dlg)//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CMy329621200__B_Dlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CMy329621200__B_Dlg)DDX_Control(pDX, IDC_EDIT2, m_Edit2);DDX_Control(pDX, IDC_EDIT1, m_Edit1);DDX_Control(pDX, IDC_UNDO_BUTTON, m_undo);DDX_Control(pDX, IDC_SHOW2_BUTTON, m_show2);DDX_Control(pDX, IDC_SHOW1_BUTTON, m_show1);DDX_Control(pDX, IDC_EXIT_BUTTON, m_exit);DDX_Control(pDX, IDC_COPY_BUTTON, m_teansfer);DDX_Control(pDX, IDC_CLEAR2_BUTTON, m_clear2);DDX_Control(pDX, IDC_CLEAR1_BUTTON, m_clear1);DDX_Control(pDX, IDC_STATIC_BMP, m_bmp);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMy329621200__B_Dlg, CDialog)//{{AFX_MSG_MAP(CMy329621200__B_Dlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_STATIC_BMP, OnStaticBmp)ON_BN_CLICKED(IDC_EXIT_BUTTON, OnExitButton)ON_BN_CLICKED(IDC_SHOW1_BUTTON, OnShow1Button)ON_BN_CLICKED(IDC_SHOW2_BUTTON, OnShow2Button)ON_BN_CLICKED(IDC_UNDO_BUTTON, OnUndoButton)ON_BN_CLICKED(IDC_CLEAR1_BUTTON, OnClear1Button)ON_BN_CLICKED(IDC_CLEAR2_BUTTON, OnClear2Button)ON_BN_CLICKED(IDC_COPY_BUTTON, OnCopyButton)ON_COMMAND(ID_Clear1, OnClear1Button)ON_COMMAND(ID_Clear2, OnClear2Button)ON_COMMAND(ID_Copy, OnCopyButton)ON_COMMAND(ID_Show1, OnShow1Button)ON_COMMAND(ID_Show2, OnShow2Button)ON_COMMAND(ID_Undo, OnUndoButton)//}}AFX_MSG_MAPEND_MESSAGE_MAP()/// CMy329621200__B_Dlg message handlersBOOL CMy329621200__B_Dlg::OnInitDialog(){CDialog::OnInitDialog();// Add "About..." menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if (!strAboutMenu.IsEmpty()){pSysMenu->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 dialogSetIcon(m_hIcon, TRUE);// Set big iconSetIcon(m_hIcon, FALSE);// Set small iconm_Menu.LoadMenu(IDR_MENU); // IDR_MENU1SetMenu(&m_Menu);// TODO: Add extra initialization herem_bmp.ModifyStyle(0,SS_BITMAP);HBITMAP hBmp=LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP1));m_bmp.SetBitmap(hBmp);return TRUE; // return TRUE unless you set the focus to a control}void CMy329621200__B_Dlg::OnSysCommand(UINT nID, LPARAM lParam){if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;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 CMy329621200__B_Dlg::OnPaint() {if (IsIconic()){CPaintDC dc(this); // device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);// Center icon in client rectangleint 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;// Draw the icondc.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 CMy329621200__B_Dlg::OnQueryDragIcon(){return (HCURSOR) m_hIcon;}void CMy329621200__B_Dlg::OnStaticBmp() {// TODO: Add your control notification handler code hereBITMAP bmp;GetObject(m_bmp.GetBitmap(),sizeof(BITMAP),&bmp);CString msg;msg.Format("Image Size %d*%d",bmp.bmWidth,bmp.bmHeight);AfxMessageBox(msg);}void CMy329621200__B_Dlg::OnExitButton() {// TODO: Add your control notification handler code hereOnOK();}void CMy329621200__B_Dlg::OnShow1Button() {// TODO: Add your control notification handler code herem_Edit1.SetSel(0,-1);// 选中编辑框IDC_EDIT1中的全部内容m_Edit1.ReplaceSel("This is the first EditBox.");}void CMy329621200__B_Dlg::OnShow2Button() {// TODO: Add your control notification handler code herem_Edit2.SetSel(0,-1);m_Edit2.ReplaceSel("This is the second EditBox.");}void CMy329621200__B_Dlg::OnUndoButton() {// TODO: Add your control notification handler code herem_Edit1.Undo();m_Edit2.Undo();}void CMy329621200__B_Dlg::OnClear1Button() {// TODO: Add your control notification handler code herem_Edit1.SetSel(0,-1);//选中IDC_EDIT1中的内容m_Edit1.ReplaceSel("");//用空串代替所选文本,即把所选的文本删除}void CMy329621200__B_Dlg::OnClear2Button() {// TODO: Add your control notification handler code herem_Edit2.SetSel(0,-1);m_Edit2.ReplaceSel("");}void CMy329621200__B_Dlg::OnCopyButton() {// TODO: Add your control notification handler code herem_Edit1.SetSel(0,-1);m_Edit1.Copy(); m_Edit2.SetSel(0,-1);m_Edit2.ReplaceSel("");m_Edit2.Paste();}void CMy329621200__B_Dlg::OnClear1() {// TODO: Add your command handler code here}void CMy329621200__B_Dlg::OnClear2() {// TODO: Add your command handler code here}void CMy329621200__B_Dlg::OnCopy() {// TODO: Add your command handler code here}void CMy329621200__B_Dlg::OnShow1() {// TODO: Add your command handler code here}void CMy329621200__B_Dlg::OnShow2() {// TODO: Add your command handler code here}void CMy329621200__B_Dlg::OnUndo() {// TODO: Add your command handler code here}

运行结果

参考文章

/weixin_42818344/article/details/98448372

/s/blog_408dea1f0102xheq.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。