- 論壇徽章:
- 1
|
- #include "stdafx.h"
- #include "MFC.h"
- #include "MFCDlg.h"
- #include "afxdialogex.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- class CAboutDlg : public CDialogEx
- {
- public:
- CAboutDlg();
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
- END_MESSAGE_MAP()
- CMFCDlg::CMFCDlg(CWnd* pParent /*=NULL*/)
- : CDialogEx(CMFCDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CMFCDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CMFCDlg, CDialogEx)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON1, &CMFCDlg::OnBnClickedButton1)
- ON_BN_CLICKED(IDC_BUTTON2, &CMFCDlg::OnBnClickedButton2)
- ON_BN_CLICKED(IDC_BUTTON3, &CMFCDlg::OnBnClickedButton3)
- ON_BN_CLICKED(IDC_BUTTON4, &CMFCDlg::OnBnClickedButton4)
- END_MESSAGE_MAP()
- BOOL CMFCDlg::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 CMFCDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialogEx::OnSysCommand(nID, lParam);
- }
- }
- void CMFCDlg::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);
- }
- else
- {
- CDialogEx::OnPaint();
- }
- }
- HCURSOR CMFCDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CMFCDlg::OnBnClickedButton1()
- {
- int left=GetDlgItemInt(IDC_LEFT);
- int right = GetDlgItemInt(IDC_RIGHT);
- SetDlgItemInt(IDC_RESULT, left + right);
- }
- void CMFCDlg::OnBnClickedButton2()
- {
- int left1 = GetDlgItemInt(IDC_LEFT1);
- int right1 = GetDlgItemInt(IDC_RIGHT1);
- SetDlgItemInt(IDC_RESULT1, left1 - right1);
- }
- void CMFCDlg::OnBnClickedButton3()
- {
- int left2 = GetDlgItemInt(IDC_LEFT2);
- int right2 = GetDlgItemInt(IDC_RIGHT2);
- SetDlgItemInt(IDC_RESULT2, left2*right2);
- }
- void CMFCDlg::OnBnClickedButton4()
- {
- int left3 = GetDlgItemInt(IDC_LEFT3);
- int right3 = GetDlgItemInt(IDC_RIGHT3);
- SetDlgItemInt(IDC_RESULT3, left3 / right3);
- }
復(fù)制代碼
- // MFCDlg.h : header file
- //
- #pragma once
- // CMFCDlg dialog
- class CMFCDlg : public CDialogEx
- {
- // Construction
- public:
- CMFCDlg(CWnd* pParent = NULL); // standard constructor
- // Dialog Data
- enum { IDD = IDD_MFC_DIALOG };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- // Implementation
- protected:
- HICON m_hIcon;
- // Generated message map functions
- virtual BOOL OnInitDialog();
- afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
- afx_msg void OnPaint();
- afx_msg HCURSOR OnQueryDragIcon();
- DECLARE_MESSAGE_MAP()
- public:
- afx_msg void OnBnClickedButton1();
- afx_msg void OnBnClickedButton2();
- afx_msg void OnBnClickedButton3();
- afx_msg void OnBnClickedButton4();
- };
復(fù)制代碼 |
|