Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.79 KB | None | 0 0
  1. // cw3Dlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "cw3.h"
  6. #include "cw3Dlg.h"
  7. #include ".\cw3dlg.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. HANDLE skrzynka;
  13. // CAboutDlg dialog used for App About
  14.  
  15. class CAboutDlg : public CDialog
  16. {
  17. public:
  18.     CAboutDlg();
  19.  
  20. // Dialog Data
  21.     enum { IDD = IDD_ABOUTBOX };
  22.  
  23.     protected:
  24.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25.  
  26. // Implementation
  27. protected:
  28.     DECLARE_MESSAGE_MAP()
  29. };
  30.  
  31. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  32. {
  33. }
  34.  
  35. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  36. {
  37.     CDialog::DoDataExchange(pDX);
  38. }
  39.  
  40. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  41. END_MESSAGE_MAP()
  42.  
  43.  
  44. // Ccw3Dlg dialog
  45.  
  46.  
  47.  
  48. Ccw3Dlg::Ccw3Dlg(CWnd* pParent /*=NULL*/)
  49.     : CDialog(Ccw3Dlg::IDD, pParent)
  50. {
  51.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  52. }
  53.  
  54. void Ccw3Dlg::DoDataExchange(CDataExchange* pDX)
  55. {
  56.     CDialog::DoDataExchange(pDX);
  57.     DDX_Control(pDX, IDC_EDIT1, ilosc_wiadomosci);
  58.     DDX_Control(pDX, IDC_EDIT3, wyslijText);
  59.     DDX_Control(pDX, IDC_EDIT4, odbierzText);
  60. }
  61.  
  62. BEGIN_MESSAGE_MAP(Ccw3Dlg, CDialog)
  63.     ON_WM_SYSCOMMAND()
  64.     ON_WM_PAINT()
  65.     ON_WM_QUERYDRAGICON()
  66.     //}}AFX_MSG_MAP
  67.     ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
  68.     ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
  69.  
  70.     ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
  71. END_MESSAGE_MAP()
  72.  
  73.  
  74. // Ccw3Dlg message handlers
  75.  
  76. BOOL Ccw3Dlg::OnInitDialog()
  77. {
  78.     CDialog::OnInitDialog();
  79.  
  80.     // Add "About..." menu item to system menu.
  81.  
  82.     // IDM_ABOUTBOX must be in the system command range.
  83.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  84.     ASSERT(IDM_ABOUTBOX < 0xF000);
  85.  
  86.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  87.     if (pSysMenu != NULL)
  88.     {
  89.         CString strAboutMenu;
  90.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  91.         if (!strAboutMenu.IsEmpty())
  92.         {
  93.             pSysMenu->AppendMenu(MF_SEPARATOR);
  94.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  95.         }
  96.     }
  97.  
  98.     // Set the icon for this dialog.  The framework does this automatically
  99.     //  when the application's main window is not a dialog
  100.     SetIcon(m_hIcon, TRUE);         // Set big icon
  101.     SetIcon(m_hIcon, FALSE);        // Set small icon
  102.  
  103.     // TODO: Add extra initialization here
  104.     CString nazwa = _T("\\\\.\\mailslot\\poczta\\wp");
  105.     skrzynka = CreateMailslot(nazwa,0,MAILSLOT_WAIT_FOREVER,0);
  106.  
  107.     return TRUE;  // return TRUE  unless you set the focus to a control
  108. }
  109.  
  110. void Ccw3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  111. {
  112.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  113.     {
  114.         CAboutDlg dlgAbout;
  115.         dlgAbout.DoModal();
  116.     }
  117.     else
  118.     {
  119.         CDialog::OnSysCommand(nID, lParam);
  120.     }
  121. }
  122.  
  123. // If you add a minimize button to your dialog, you will need the code below
  124. //  to draw the icon.  For MFC applications using the document/view model,
  125. //  this is automatically done for you by the framework.
  126.  
  127. void Ccw3Dlg::OnPaint()
  128. {
  129.     if (IsIconic())
  130.     {
  131.         CPaintDC dc(this); // device context for painting
  132.  
  133.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  134.  
  135.         // Center icon in client rectangle
  136.         int cxIcon = GetSystemMetrics(SM_CXICON);
  137.         int cyIcon = GetSystemMetrics(SM_CYICON);
  138.         CRect rect;
  139.         GetClientRect(&rect);
  140.         int x = (rect.Width() - cxIcon + 1) / 2;
  141.         int y = (rect.Height() - cyIcon + 1) / 2;
  142.  
  143.         // Draw the icon
  144.         dc.DrawIcon(x, y, m_hIcon);
  145.     }
  146.     else
  147.     {
  148.         CDialog::OnPaint();
  149.     }
  150. }
  151.  
  152. // The system calls this function to obtain the cursor to display while the user drags
  153. //  the minimized window.
  154. HCURSOR Ccw3Dlg::OnQueryDragIcon()
  155. {
  156.     return static_cast<HCURSOR>(m_hIcon);
  157. }
  158.  
  159.  
  160. void Ccw3Dlg::OnBnClickedButton1()
  161. {
  162.     CString nazwa = _T("\\\\.\\mailslot\\poczta\\wp");
  163.     CFile plik(nazwa, CFile::modeWrite + CFile::shareDenyNone);
  164.     CString wiadomosc;
  165.     wyslijText.GetWindowText(wiadomosc);
  166.     plik.Write(LPCTSTR(wiadomosc),wiadomosc.GetLength() + sizeof(TCHAR));
  167.         // TODO: Add your control notification handler code here
  168. }
  169.  
  170. void Ccw3Dlg::OnBnClickedButton2()
  171. {
  172.     unsigned long maxSize, nextSize, messageCount;
  173.     GetMailslotInfo(skrzynka,&maxSize, &nextSize, &messageCount, NULL);
  174.  
  175.     CString ilosc;
  176.     ilosc.Format(_T("%d"), messageCount);
  177.  
  178.     ilosc_wiadomosci.SetWindowText(ilosc);
  179.     // TODO: Add your control notification handler code here
  180. }
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187. void Ccw3Dlg::OnBnClickedButton3()
  188. {
  189.     CFile poczta(skrzynka);
  190.     CString tekst;
  191.     char wiad[1024] = {'\0'};
  192.     CString w[1024];
  193.  
  194.  
  195.     unsigned long messageCount;
  196.     GetMailslotInfo(skrzynka, NULL, NULL, &messageCount, NULL);
  197.     for( int i=0; i < messageCount;++i){
  198.         poczta.Read(wiad,1024);
  199.         CString t;
  200.         t.Format (_T("%s"), wiad);
  201.         tekst +=t;
  202.         w[i] = t;
  203.         tekst +=_T("\r\n");
  204.     }
  205.     CString name = _T("\\\\.\\mailslot\\poczta\\wp");
  206.     CFile p(name,CFile::modeWrite + CFile::shareDenyNone);
  207.     for (int i = 0; i < messageCount; i++){
  208.     p.Write(LPCTSTR(w[i]), w[i].GetLength() + sizeof(TCHAR));
  209.     }
  210.     odbierzText.SetWindowText(tekst);
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement