Advertisement
Guest User

Untitled

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