Advertisement
ElfikCo

SO Ćw3 B

Dec 13th, 2019
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.96 KB | None | 0 0
  1. // Dlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "SO3.h"
  6. #include "Dlg.h"
  7. #include ".\dlg.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12.  
  13. HANDLE hskrzynki;
  14. CString adres;
  15.  
  16. // CAboutDlg dialog used for App About
  17.  
  18. class CAboutDlg : public CDialog
  19. {
  20. public:
  21.     CAboutDlg();
  22.  
  23. // Dialog Data
  24.     enum { IDD = IDD_ABOUTBOX };
  25.  
  26.     protected:
  27.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  28.  
  29. // Implementation
  30. protected:
  31.     DECLARE_MESSAGE_MAP()
  32. };
  33.  
  34. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  35. {
  36. }
  37.  
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40.     CDialog::DoDataExchange(pDX);
  41. }
  42.  
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. END_MESSAGE_MAP()
  45.  
  46.  
  47. // Dlg dialog
  48.  
  49.  
  50.  
  51. Dlg::Dlg(CWnd* pParent /*=NULL*/)
  52.     : CDialog(Dlg::IDD, pParent)
  53. {
  54.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  55. }
  56.  
  57. void Dlg::DoDataExchange(CDataExchange* pDX)
  58. {
  59.     CDialog::DoDataExchange(pDX);
  60.     DDX_Control(pDX, IDC_EDIT1, m_ekran);
  61.     DDX_Control(pDX, IDC_EDIT2, m_lwiad);
  62.     DDX_Control(pDX, IDC_EDIT3, m_input);
  63. }
  64.  
  65. BEGIN_MESSAGE_MAP(Dlg, CDialog)
  66.     ON_WM_SYSCOMMAND()
  67.     ON_WM_PAINT()
  68.     ON_WM_QUERYDRAGICON()
  69.     //}}AFX_MSG_MAP
  70.     ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedSprawdz)
  71.     ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedWyslij)
  72. END_MESSAGE_MAP()
  73.  
  74.  
  75. // Dlg message handlers
  76.  
  77. BOOL Dlg::OnInitDialog()
  78. {
  79.     CDialog::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.         CString strAboutMenu;
  91.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  92.         if (!strAboutMenu.IsEmpty())
  93.         {
  94.             pSysMenu->AppendMenu(MF_SEPARATOR);
  95.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  96.         }
  97.     }
  98.  
  99.     // Set the icon for this dialog.  The framework does this automatically
  100.     //  when the application's main window is not a dialog
  101.     SetIcon(m_hIcon, TRUE);         // Set big icon
  102.     SetIcon(m_hIcon, FALSE);        // Set small icon
  103.  
  104.     // TODO: Add extra initialization here
  105.  
  106.     adres = "\\\\.\\mailslot\\skrzynka";
  107.     hskrzynki = CreateMailslot(adres, 0, 0, NULL);
  108.     if(hskrzynki == INVALID_HANDLE_VALUE){
  109.         MessageBox("Nieudana próva utworzenia skrzynki");
  110.         EndDialog(1);
  111.     }
  112.     return TRUE;  // return TRUE  unless you set the focus to a control
  113. }
  114.  
  115. void Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  116. {
  117.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  118.     {
  119.         CAboutDlg dlgAbout;
  120.         dlgAbout.DoModal();
  121.     }
  122.     else
  123.     {
  124.         CDialog::OnSysCommand(nID, lParam);
  125.     }
  126. }
  127.  
  128. // If you add a minimize button to your dialog, you will need the code below
  129. //  to draw the icon.  For MFC applications using the document/view model,
  130. //  this is automatically done for you by the framework.
  131.  
  132. void Dlg::OnPaint()
  133. {
  134.     if (IsIconic())
  135.     {
  136.         CPaintDC dc(this); // device context for painting
  137.  
  138.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  139.  
  140.         // Center icon in client rectangle
  141.         int cxIcon = GetSystemMetrics(SM_CXICON);
  142.         int cyIcon = GetSystemMetrics(SM_CYICON);
  143.         CRect rect;
  144.         GetClientRect(&rect);
  145.         int x = (rect.Width() - cxIcon + 1) / 2;
  146.         int y = (rect.Height() - cyIcon + 1) / 2;
  147.  
  148.         // Draw the icon
  149.         dc.DrawIcon(x, y, m_hIcon);
  150.     }
  151.     else
  152.     {
  153.         CDialog::OnPaint();
  154.     }
  155. }
  156.  
  157. // The system calls this function to obtain the cursor to display while the user drags
  158. //  the minimized window.
  159. HCURSOR Dlg::OnQueryDragIcon()
  160. {
  161.     return static_cast<HCURSOR>(m_hIcon);
  162. }
  163.  
  164. void Dlg::OnBnClickedSprawdz()
  165. {
  166.     CString ekran;
  167.     unsigned long liczbawiad;
  168.     GetMailslotInfo(hskrzynki, NULL, NULL, &liczbawiad, NULL);
  169.     ekran.AppendFormat("%d", liczbawiad);
  170.     m_lwiad.SetWindowText(ekran);
  171.  
  172. }
  173.  
  174. void Dlg::OnBnClickedWyslij()
  175. {
  176.     CString message, bufor;
  177.     CFile skrzynka(adres, CFile::modeWrite + CFile::shareDenyNone);
  178.     m_input.GetWindowText(message);
  179.     skrzynka.Write(message.GetBuffer(), sizeof(message));
  180.     skrzynka.Close();
  181.     m_input.SetWindowText("");
  182.  
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement