Advertisement
ElfikCo

SO 4

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