Advertisement
ElfikCo

SO Ćw3 C

Dec 13th, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.40 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.     ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedOdczytaj)
  73. END_MESSAGE_MAP()
  74.  
  75.  
  76. // Dlg message handlers
  77.  
  78. BOOL Dlg::OnInitDialog()
  79. {
  80.     CDialog::OnInitDialog();
  81.  
  82.     // Add "About..." menu item to system menu.
  83.  
  84.     // IDM_ABOUTBOX must be in the system command range.
  85.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  86.     ASSERT(IDM_ABOUTBOX < 0xF000);
  87.  
  88.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  89.     if (pSysMenu != NULL)
  90.     {
  91.         CString strAboutMenu;
  92.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  93.         if (!strAboutMenu.IsEmpty())
  94.         {
  95.             pSysMenu->AppendMenu(MF_SEPARATOR);
  96.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  97.         }
  98.     }
  99.  
  100.     // Set the icon for this dialog.  The framework does this automatically
  101.     //  when the application's main window is not a dialog
  102.     SetIcon(m_hIcon, TRUE);         // Set big icon
  103.     SetIcon(m_hIcon, FALSE);        // Set small icon
  104.  
  105.     // TODO: Add extra initialization here
  106.  
  107.     adres = "\\\\.\\mailslot\\skrzynka";
  108.     hskrzynki = CreateMailslot(adres, 1024, 0, NULL);
  109.     if(hskrzynki == INVALID_HANDLE_VALUE){
  110.         MessageBox("Nieudana próva utworzenia skrzynki");
  111.         EndDialog(1);
  112.     }
  113.     return TRUE;  // return TRUE  unless you set the focus to a control
  114. }
  115.  
  116. void Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  117. {
  118.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  119.     {
  120.         CAboutDlg dlgAbout;
  121.         dlgAbout.DoModal();
  122.     }
  123.     else
  124.     {
  125.         CDialog::OnSysCommand(nID, lParam);
  126.     }
  127. }
  128.  
  129. // If you add a minimize button to your dialog, you will need the code below
  130. //  to draw the icon.  For MFC applications using the document/view model,
  131. //  this is automatically done for you by the framework.
  132.  
  133. void Dlg::OnPaint()
  134. {
  135.     if (IsIconic())
  136.     {
  137.         CPaintDC dc(this); // device context for painting
  138.  
  139.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  140.  
  141.         // Center icon in client rectangle
  142.         int cxIcon = GetSystemMetrics(SM_CXICON);
  143.         int cyIcon = GetSystemMetrics(SM_CYICON);
  144.         CRect rect;
  145.         GetClientRect(&rect);
  146.         int x = (rect.Width() - cxIcon + 1) / 2;
  147.         int y = (rect.Height() - cyIcon + 1) / 2;
  148.  
  149.         // Draw the icon
  150.         dc.DrawIcon(x, y, m_hIcon);
  151.     }
  152.     else
  153.     {
  154.         CDialog::OnPaint();
  155.     }
  156. }
  157.  
  158. // The system calls this function to obtain the cursor to display while the user drags
  159. //  the minimized window.
  160. HCURSOR Dlg::OnQueryDragIcon()
  161. {
  162.     return static_cast<HCURSOR>(m_hIcon);
  163. }
  164.  
  165. void Dlg::OnBnClickedSprawdz()
  166. {
  167.     CString ekran;
  168.     unsigned long liczbawiad;
  169.     GetMailslotInfo(hskrzynki, NULL, NULL, &liczbawiad, NULL);
  170.     ekran.AppendFormat("%d", liczbawiad);
  171.     m_lwiad.SetWindowText(ekran);
  172.  
  173. }
  174.  
  175. void Dlg::OnBnClickedWyslij()
  176. {
  177.     CString message, bufor;
  178.     CFile skrzynka(adres, CFile::modeWrite + CFile::shareDenyNone);
  179.     m_input.GetWindowText(message);
  180.     skrzynka.Write(message.GetBuffer(), message.GetLength() + 1);
  181.     m_input.SetWindowText(NULL);
  182. }
  183.  
  184. void Dlg::OnBnClickedOdczytaj()
  185. {
  186.     CString message;
  187.     CFile skrzynka(hskrzynki);
  188.     char wiesc[1024];
  189.     //CFile skrzynka(adres, CFile::modeRead + CFile::shareDenyNone);
  190.     DWORD w1, w2, w3, w4;
  191.     GetMailslotInfo(hskrzynki, NULL, NULL, &w3, NULL);
  192.     for(int i = 0; i < w3; i++){
  193.         skrzynka.Read(wiesc, 1024);
  194.         message.AppendFormat("%s\r\n", wiesc);
  195.     }
  196.     if(w3)
  197.         m_ekran.SetWindowText(message);
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement