Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.26 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.    
  117.     return TRUE;  // return TRUE  unless you set the focus to a control
  118. }
  119.  
  120. void COkno::OnSysCommand(UINT nID, LPARAM lParam)
  121. {
  122.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  123.     {
  124.         CAboutDlg dlgAbout;
  125.         dlgAbout.DoModal();
  126.     }
  127.     else
  128.     {
  129.         CDialog::OnSysCommand(nID, lParam);
  130.     }
  131. }
  132.  
  133. // If you add a minimize button to your dialog, you will need the code below
  134. //  to draw the icon.  For MFC applications using the document/view model,
  135. //  this is automatically done for you by the framework.
  136.  
  137. void COkno::OnPaint()
  138. {
  139.     if (IsIconic())
  140.     {
  141.         CPaintDC dc(this); // device context for painting
  142.  
  143.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  144.  
  145.         // Center icon in client rectangle
  146.         int cxIcon = GetSystemMetrics(SM_CXICON);
  147.         int cyIcon = GetSystemMetrics(SM_CYICON);
  148.         CRect rect;
  149.         GetClientRect(&rect);
  150.         int x = (rect.Width() - cxIcon + 1) / 2;
  151.         int y = (rect.Height() - cyIcon + 1) / 2;
  152.  
  153.         // Draw the icon
  154.         dc.DrawIcon(x, y, m_hIcon);
  155.     }
  156.     else
  157.     {
  158.         CDialog::OnPaint();
  159.     }
  160. }
  161.  
  162. // The system calls this function to obtain the cursor to display while the user drags
  163. //  the minimized window.
  164. HCURSOR COkno::OnQueryDragIcon()
  165. {
  166.     return static_cast<HCURSOR>(m_hIcon);
  167. }
  168.  
  169. void COkno::OnTimer(UINT nIDEvent)
  170. {
  171.     //TODO: Sprawdzenie czy jest nowa wiadomosc w skrzynce
  172.  
  173.     CDialog::OnTimer(nIDEvent);
  174. }
  175.  
  176. void COkno::OnBnClickedOdswiez()
  177. {
  178.     char buffer[1024]="";
  179.  
  180.     /*TODO: Pobranie listy zarejestrowanych skrzynek*/
  181.     char * zadanie = (char*) malloc(OPER_SIZE);
  182.     char * odpowiedz = (char*) malloc(OPER_SIZE);
  183.     memset(odpowiedz, 0, OPER_SIZE);
  184.     strcpy(zadanie, "GET");
  185.     DWORD odp_size;
  186.     if (CallNamedPipe("\\\\.\\pipe\\sysopnp",zadanie, strlen(zadanie)+1,odpowiedz,OPER_SIZE,&odp_size,3000))
  187.     {
  188.       char *p=odpowiedz;
  189.       while(*p)
  190.       {
  191.            if (*p=='\n') {*p='\0';
  192.                 p++;
  193.             }
  194.         p=odpowiedz;
  195.         int l;
  196.         m_lista.ResetContent();
  197.          while (l=strlen(p))
  198.           {
  199.             m_lista.AddString(p);
  200.             p+=l+1;
  201.           }
  202.       }}
  203.     else
  204.      {
  205.       sprintf(zadanie, "blad transakcji 0x%X",GetLastError());
  206.       MessageBox(zadanie, "Potok",16);
  207.      }
  208.      free(zadanie);
  209.      free(odpowiedz);}
  210.  
  211. void COkno::OnBnClickedWyslij()
  212. {
  213.     char buffer[128];
  214.     m_lista.GetWindowText(buffer,128);
  215.  
  216.     //TODO: Wyslanie wiadomosci do wybranej skrzynki
  217.  
  218. }
  219.  
  220. afx_msg LRESULT COkno::OnWiadomosc(WPARAM n, LPARAM m)
  221. {
  222.     //TODO: Odbior przeslanego kodu
  223.  
  224.     return 0;
  225. }
  226.  
  227. void COkno::OnBnClickedZaliczamy()
  228. {
  229.     /*TODO: Utworzenie zdarzenia "koniec ćwiczenia" i ustawienie jego stanu na dostepny*/
  230.  
  231. }
  232.  
  233. void COkno::OnDestroy()
  234. {
  235.     KillTimer(1);
  236.     CDialog::OnDestroy();
  237. }
  238.  
  239. void COkno::OnBnClickedKoniec()
  240. {
  241. EndDialog(1);
  242. }
  243.  
  244. void COkno::OnCbnSelchangeLista()
  245. {
  246.     // TODO: Add your control notification handler code here
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement