Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.13 KB | None | 0 0
  1. // Okno.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "lab4.h"
  6. #include "Okno.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11.  
  12. static UINT NEAR WM_LAB4 = RegisterWindowMessage("WM_SYSTOPER_LAB4");
  13.  
  14. // CAboutDlg dialog used  for App About
  15.  
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19.     CAboutDlg();
  20.  
  21. // Dialog Data
  22.     enum { IDD = IDD_ABOUTBOX };
  23.  
  24.     protected:
  25.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  26.  
  27. // Implementation
  28. protected:
  29.     DECLARE_MESSAGE_MAP()
  30. };
  31.  
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. }
  35.  
  36. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CDialog::DoDataExchange(pDX);
  39. }
  40.  
  41. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  42. END_MESSAGE_MAP()
  43.  
  44.  
  45. // COkno dialog
  46.  
  47.  
  48.  
  49. COkno::COkno(CWnd* pParent /*=NULL*/)
  50.     : CDialog(COkno::IDD, pParent)
  51. {
  52.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  53. }
  54.  
  55. void COkno::DoDataExchange(CDataExchange* pDX)
  56. {
  57.     CDialog::DoDataExchange(pDX);
  58.     DDX_Control(pDX, IDC_EKRAN, m_ekran);
  59.     DDX_Control(pDX, IDC_LISTA, m_lista);
  60.     DDX_Control(pDX, IDC_ODSWIEZ, m_odswiez);
  61. }
  62.  
  63. BEGIN_MESSAGE_MAP(COkno, CDialog)
  64.     ON_WM_SYSCOMMAND()
  65.     ON_WM_PAINT()
  66.     ON_WM_QUERYDRAGICON()
  67.     //}}AFX_MSG_MAP
  68.     ON_WM_TIMER()
  69.     ON_REGISTERED_MESSAGE(WM_LAB4,OnWiadomosc)
  70.     ON_BN_CLICKED(IDC_ODSWIEZ, OnBnClickedOdswiez)
  71.     ON_BN_CLICKED(IDC_WYSLIJ, OnBnClickedWyslij)
  72.     ON_BN_CLICKED(IDC_ZALICZAMY, OnBnClickedZaliczamy)
  73.     ON_WM_DESTROY()
  74.     ON_BN_CLICKED(IDC_KONIEC, OnBnClickedKoniec)
  75. END_MESSAGE_MAP()
  76.  
  77.  
  78. // COkno message handlers
  79.  
  80. BOOL COkno::OnInitDialog()
  81. {
  82.     CDialog::OnInitDialog();
  83.  
  84.     // Add "About..." menu item to system menu.
  85.  
  86.     // IDM_ABOUTBOX must be in the system command range.
  87.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  88.     ASSERT(IDM_ABOUTBOX < 0xF000);
  89.  
  90.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  91.     if (pSysMenu != NULL)
  92.     {
  93.         CString strAboutMenu;
  94.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  95.         if (!strAboutMenu.IsEmpty())
  96.         {
  97.             pSysMenu->AppendMenu(MF_SEPARATOR);
  98.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99.         }
  100.     }
  101.  
  102.     // Set the icon for this dialog.  The framework does this automatically
  103.     //  when the application's main window is not a dialog
  104.     SetIcon(m_hIcon, TRUE);         // Set big icon
  105.     SetIcon(m_hIcon, FALSE);        // Set small icon
  106.  
  107.     // Add extra initialization here
  108.  
  109.     srand((unsigned)time(0));
  110.     SetTimer(1,500,0);
  111.  
  112.     //TODO: Utworzenie skrzynki pocztowej i jej rejestracja potokiem nazwanym
  113.     char buffer[100] = "PUT wiadomosc";
  114.     char out[100];
  115.     unsigned long odp;
  116.  
  117.     ID = CreateMailslot("\\\\.\\mailslot\\fd3\\systemy_\\lab.spr", 0, MAILSLOT_WAIT_FOREVER, 0);
  118.     CallNamedPipe("\\\\.\\pipe\\sysopnp", (void*)buffer, 100, (void*) out, 100, &odp, NMPWAIT_USE_DEFAULT_WAIT);
  119.    
  120.     return TRUE;  // return TRUE  unless you set the focus to a control
  121. }
  122.  
  123. void COkno::OnSysCommand(UINT nID, LPARAM lParam)
  124. {
  125.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  126.     {
  127.         CAboutDlg dlgAbout;
  128.         dlgAbout.DoModal();
  129.     }
  130.     else
  131.     {
  132.         CDialog::OnSysCommand(nID, lParam);
  133.     }
  134. }
  135.  
  136. // If you add a minimize button to your dialog, you will need the code below
  137. //  to draw the icon.  For MFC applications using the document/view model,
  138. //  this is automatically done for you by the framework.
  139.  
  140. void COkno::OnPaint()
  141. {
  142.     if (IsIconic())
  143.     {
  144.         CPaintDC dc(this); // device context for painting
  145.  
  146.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  147.  
  148.         // Center icon in client rectangle
  149.         int cxIcon = GetSystemMetrics(SM_CXICON);
  150.         int cyIcon = GetSystemMetrics(SM_CYICON);
  151.         CRect rect;
  152.         GetClientRect(&rect);
  153.         int x = (rect.Width() - cxIcon + 1) / 2;
  154.         int y = (rect.Height() - cyIcon + 1) / 2;
  155.  
  156.         // Draw the icon
  157.         dc.DrawIcon(x, y, m_hIcon);
  158.     }
  159.     else
  160.     {
  161.         CDialog::OnPaint();
  162.     }
  163. }
  164.  
  165. // The system calls this function to obtain the cursor to display while the user drags
  166. //  the minimized window.
  167. HCURSOR COkno::OnQueryDragIcon()
  168. {
  169.     return static_cast<HCURSOR>(m_hIcon);
  170. }
  171.  
  172. void COkno::OnTimer(UINT nIDEvent)
  173. {
  174.     //TODO: Sprawdzenie czy jest nowa wiadomosc w skrzynce
  175.     unsigned long messageCount;
  176.  
  177.     GetMailslotInfo(ID, NULL, NULL, &messageCount, NULL);
  178.  
  179.     if(messageCount > 0) {
  180.         CFile file(ID);
  181.         char buffer[100];
  182.         file.Read((void *)buffer, 100);
  183.         m_ekran.SetWindowText(buffer);
  184.     }
  185.  
  186.     CDialog::OnTimer(nIDEvent);
  187. }
  188.  
  189. void COkno::OnBnClickedOdswiez()
  190. {
  191.     char buffer[1024]="GET";
  192.     char out[1024];
  193.     unsigned long odp;
  194.  
  195.     /*TODO: Pobranie listy zarejestrowanych skrzynek*/
  196.     CallNamedPipe("\\\\.\\pipe\\sysopnp", (void*)buffer, 100, (void*)out, 100, &odp, NMPWAIT_USE_DEFAULT_WAIT);
  197.  
  198.     strtok();
  199.  
  200.     for(int i = atof(count); i>= 0; i--) {
  201.         m_lista.AddString(out);
  202.     }
  203.  
  204.    
  205. }
  206.  
  207. void COkno::OnBnClickedWyslij()
  208. {
  209.     char buffer[128];
  210.     m_lista.GetWindowText(buffer,128);
  211.  
  212.     //TODO: Wyslanie wiadomosci do wybranej skrzynki
  213.    
  214. }
  215.  
  216. afx_msg LRESULT COkno::OnWiadomosc(WPARAM n, LPARAM m)
  217. {
  218.     //TODO: Odbior przeslanego kodu
  219.  
  220.     return 0;
  221. }
  222.  
  223. void COkno::OnBnClickedZaliczamy()
  224. {
  225.     /*TODO: Utworzenie zdarzenia "koniec ćwiczenia" i ustawienie jego stanu na dostepny*/
  226.  
  227. }
  228.  
  229. void COkno::OnDestroy()
  230. {
  231.     KillTimer(1);
  232.     CDialog::OnDestroy();
  233. }
  234.  
  235. void COkno::OnBnClickedKoniec()
  236. {
  237. EndDialog(1);
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement