Facebook
From pk, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 254
  1.  
  2. // MFCApplication2Dlg.cpp : implementation file
  3. //
  4.  
  5. #include "stdafx.h"
  6. #include "MFCApplication2.h"
  7. #include "MFCApplication2Dlg.h"
  8. #include "afxdialogex.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #endif
  13.  
  14.  
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialogEx
  18. {
  19. public:
  20.         CAboutDlg();
  21.  
  22. // Dialog Data
  23.         enum { IDD = IDD_ABOUTBOX };
  24.  
  25.         protected:
  26.         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  27.  
  28. // Implementation
  29. protected:
  30.         DECLARE_MESSAGE_MAP()
  31. };
  32.  
  33. CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
  34. {
  35. }
  36.  
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39.         CDialogEx::DoDataExchange(pDX);
  40. }
  41.  
  42. BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
  43. END_MESSAGE_MAP()
  44.  
  45.  
  46. // CMFCApplication2Dlg dialog
  47.  
  48.  
  49.  
  50. CMFCApplication2Dlg::CMFCApplication2Dlg(CWnd* pParent /*=NULL*/)
  51.         : CDialogEx(CMFCApplication2Dlg::IDD, pParent)
  52. {
  53.         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  54. }
  55.  
  56. void CMFCApplication2Dlg::DoDataExchange(CDataExchange* pDX)
  57. {
  58.         CDialogEx::DoDataExchange(pDX);
  59.         DDX_Control(pDX, IDC_EDIT1, wartosc1);
  60.         DDX_Control(pDX, IDC_EDIT2, wartosc2);
  61.         DDX_Control(pDX, IDC_TEXT, wynik);
  62. }
  63.  
  64. BEGIN_MESSAGE_MAP(CMFCApplication2Dlg, CDialogEx)
  65.         ON_WM_SYSCOMMAND()
  66.         ON_WM_PAINT()
  67.         ON_WM_QUERYDRAGICON()
  68.         ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication2Dlg::OnBnClickedButton1)
  69.         ON_BN_CLICKED(IDC_BUTTON2, &CMFCApplication2Dlg::OnBnClickedButton2)
  70.         ON_BN_CLICKED(IDC_BUTTON3, &CMFCApplication2Dlg::OnBnClickedButton3)
  71.         ON_BN_CLICKED(IDC_BUTTON4, &CMFCApplication2Dlg::OnBnClickedButton4)
  72. END_MESSAGE_MAP()
  73.  
  74.  
  75. // CMFCApplication2Dlg message handlers
  76.  
  77. BOOL CMFCApplication2Dlg::OnInitDialog()
  78. {
  79.         CDialogEx::OnInitDialog();
  80.  
  81.         // Add "About..." menu item to system menu.
  82.  
  83.         // IDM_ABOUTBOX must be in the system command range.
  84.         ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  85.         ASSERT(IDM_ABOUTBOX < 0xF000);
  86.  
  87.         CMenu* pSysMenu = GetSystemMenu(FALSE);
  88.         if (pSysMenu != NULL)
  89.         {
  90.                 BOOL bNameValid;
  91.                 CString strAboutMenu;
  92.                 bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  93.                 ASSERT(bNameValid);
  94.                 if (!strAboutMenu.IsEmpty())
  95.                 {
  96.                         pSysMenu->AppendMenu(MF_SEPARATOR);
  97.                         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  98.                 }
  99.         }
  100.  
  101.         // Set the icon for this dialog.  The framework does this automatically
  102.         //  when the application's main window is not a dialog
  103.         SetIcon(m_hIcon, TRUE);                 // Set big icon
  104.         SetIcon(m_hIcon, FALSE);                // Set small icon
  105.  
  106.         // TODO: Add extra initialization here
  107.  
  108.         return TRUE;  // return TRUE  unless you set the focus to a control
  109. }
  110.  
  111. void CMFCApplication2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  112. {
  113.         if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  114.         {
  115.                 CAboutDlg dlgAbout;
  116.                 dlgAbout.DoModal();
  117.         }
  118.         else
  119.         {
  120.                 CDialogEx::OnSysCommand(nID, lParam);
  121.         }
  122. }
  123.  
  124. // If you add a minimize button to your dialog, you will need the code below
  125. //  to draw the icon.  For MFC applications using the document/view model,
  126. //  this is automatically done for you by the framework.
  127.  
  128. void CMFCApplication2Dlg::OnPaint()
  129. {
  130.         if (IsIconic())
  131.         {
  132.                 CPaintDC dc(this); // device context for painting
  133.  
  134.                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  135.  
  136.                 // Center icon in client rectangle
  137.                 int cxIcon = GetSystemMetrics(SM_CXICON);
  138.                 int cyIcon = GetSystemMetrics(SM_CYICON);
  139.                 CRect rect;
  140.                 GetClientRect(&rect);
  141.                 int x = (rect.Width() - cxIcon + 1) / 2;
  142.                 int y = (rect.Height() - cyIcon + 1) / 2;
  143.  
  144.                 // Draw the icon
  145.                 dc.DrawIcon(x, y, m_hIcon);
  146.         }
  147.         else
  148.         {
  149.                 CDialogEx::OnPaint();
  150.         }
  151. }
  152.  
  153. // The system calls this function to obtain the cursor to display while the user drags
  154. //  the minimized window.
  155. HCURSOR CMFCApplication2Dlg::OnQueryDragIcon()
  156. {
  157.         return static_cast<HCURSOR>(m_hIcon);
  158. }
  159.  
  160.  
  161.  
  162. void CMFCApplication2Dlg::OnBnClickedButton1()
  163. {
  164.         // TODO: Add your control notification handler code here
  165.  
  166.         CString temp1;
  167.         CString temp2;
  168.         CString temp;
  169.  
  170.         wartosc1.GetWindowTextW(temp1);
  171.         wartosc2.GetWindowTextW(temp2);
  172.  
  173.         int wartosc1 = _ttoi(temp1);
  174.         int wartosc2 = _ttoi(temp2);
  175.  
  176.         int wynik1 = wartosc1 + wartosc2;
  177.  
  178.         temp.Format(_T("Wynik %i"), wynik1);
  179.        
  180.         wynik.SetWindowTextW(temp);
  181.        
  182.  
  183. }
  184.  
  185.  
  186. void CMFCApplication2Dlg::OnBnClickedButton2()
  187. {
  188.         // TODO: Add your control notification handler code here
  189.  
  190.         CString temp1;
  191.         CString temp2;
  192.         CString temp;
  193.  
  194.         wartosc1.GetWindowTextW(temp1);
  195.         wartosc2.GetWindowTextW(temp2);
  196.  
  197.         int wartosc1 = _ttoi(temp1);
  198.         int wartosc2 = _ttoi(temp2);
  199.  
  200.         int wynik1 = wartosc1 - wartosc2;
  201.  
  202.         temp.Format(_T("Wynik %i"), wynik1);
  203.         wynik.SetWindowTextW(temp);
  204.  
  205. }
  206.  
  207.  
  208. void CMFCApplication2Dlg::OnBnClickedButton3()
  209. {
  210.         // TODO: Add your control notification handler code here
  211.         CString temp1;
  212.         CString temp2;
  213.         CString temp;
  214.  
  215.         wartosc1.GetWindowTextW(temp1);
  216.         wartosc2.GetWindowTextW(temp2);
  217.  
  218.         int wartosc1 = _ttoi(temp1);
  219.         int wartosc2 = _ttoi(temp2);
  220.  
  221.         int wynik1 = wartosc1 * wartosc2;
  222.  
  223.         temp.Format(_T("Wynik %i"), wynik1);
  224.         wynik.SetWindowTextW(temp);
  225. }
  226.  
  227.  
  228. void CMFCApplication2Dlg::OnBnClickedButton4()
  229. {
  230.         // TODO: Add your control notification handler code here
  231.         CString temp1;
  232.         CString temp2;
  233.         CString temp;
  234.  
  235.         wartosc1.GetWindowTextW(temp1);
  236.         wartosc2.GetWindowTextW(temp2);
  237.  
  238.         int wartosc1 = _ttoi(temp1);
  239.         int wartosc2 = _ttoi(temp2);
  240.  
  241.         int wynik1 = wartosc1 / wartosc2;
  242.  
  243.         temp.Format(_T("Wynik %i"), wynik1);
  244.         wynik.SetWindowTextW(temp);
  245. }
  246.