Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SO4LABDlg.cpp : implementation file
- //
- #include "pch.h"
- #include "framework.h"
- #include "SO4LAB.h"
- #include "SO4LABDlg.h"
- #include "afxdialogex.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- HANDLE h_skrzynka;
- static UINT NEAR WM_LAB4 = RegisterWindowMessage("WM_SYSTOPER_LAB4");
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialogEx
- {
- public:
- CAboutDlg();
- // Dialog Data
- #ifdef AFX_DESIGN_TIME
- enum { IDD = IDD_ABOUTBOX };
- #endif
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- // Implementation
- protected:
- DECLARE_MESSAGE_MAP()
- public:
- // afx_msg void OnTimer(UINT nIDEvent);
- // void OnBnClickedOdswierz();
- // afx_msg void OnBnClickedWyslij();
- // afx_msg void OnBnClickedZaliczamy();
- // afx_msg void OnBnClickedKoniec();
- };
- CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
- END_MESSAGE_MAP()
- // CSO4LABDlg dialog
- CSO4LABDlg::CSO4LABDlg(CWnd* pParent /*=nullptr*/)
- : CDialogEx(IDD_SO4LAB_DIALOG, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CSO4LABDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_EDIT1, m_ekran);
- DDX_Control(pDX, IDC_BUTTON1, m_odswiez);
- DDX_Control(pDX, IDC_BUTTON2, m_koniec);
- DDX_Control(pDX, IDC_BUTTON3, m_zaliczamy);
- DDX_Control(pDX, IDC_BUTTON4, m_wyslij);
- DDX_Control(pDX, IDC_COMBO1, m_lista);
- }
- BEGIN_MESSAGE_MAP(CSO4LABDlg, CDialogEx)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_TIMER()
- ON_REGISTERED_MESSAGE(WM_LAB4, OnWiadomosc)
- ON_BN_CLICKED(IDC_BUTTON1, &CSO4LABDlg::OnBnClickedOdswiez)
- ON_BN_CLICKED(IDC_BUTTON4, &CSO4LABDlg::OnBnClickedWyslij)
- ON_BN_CLICKED(IDC_BUTTON3, &CSO4LABDlg::OnBnClickedZaliczamy)
- ON_BN_CLICKED(IDC_BUTTON2, &CSO4LABDlg::OnBnClickedKoniec)
- END_MESSAGE_MAP()
- // CSO4LABDlg message handlers
- BOOL CSO4LABDlg::OnInitDialog()
- {
- CDialogEx::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != nullptr)
- {
- BOOL bNameValid;
- CString strAboutMenu;
- bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
- ASSERT(bNameValid);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- srand((unsigned)time(0));
- SetTimer(1,500,0);
- //Nazewnictwo skrzynki
- CString w, nazwaSkrzynki;
- DWORD odpowiedzRozmiar;
- CallNamedPipeA("\\\\.\\pipe\\sysopnp", "GET", 4, w.GetBufferSetLength(8192), 8192, &odpowiedzRozmiar, 3000);
- nazwaSkrzynki.AppendFormat("\\\\.\\mailslot\\skrzynka%c", w[0]);
- //Zmiana nazwy okna
- CString nazwaOkna;
- AfxGetMainWnd()->GetWindowTextA(nazwaOkna);
- nazwaOkna.AppendFormat("Skrzynka %c", w[0]);
- AfxGetMainWnd()->SetWindowTextA(nazwaOkna);
- //Tworzenie skrzynki
- h_skrzynka = CreateMailslot(nazwaSkrzynki, 1024, 0, NULL);
- if (h_skrzynka == NULL)
- MessageBox("Nieudana próba utworzenia skrzynki!");
- else {
- DWORD d;
- CString w1 = "PUT ";
- w1.Append(nazwaSkrzynki);
- char* w2 = new char[1024];
- memset(w2, 0, 1024);
- if (!CallNamedPipeA("\\\\.\\pipe\\sysopnp", w1.GetBuffer() , w1.GetLength() + 1, w2, 1024, &d, 3000)) {
- MessageBox("Blad w transakcji");
- }
- delete[] w2;
- }
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CSO4LABDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialogEx::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CSO4LABDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialogEx::OnPaint();
- }
- }
- // The system calls this function to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CSO4LABDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CSO4LABDlg::OnTimer(UINT nIDEvent)
- {
- DWORD lWiad = 0;
- GetMailslotInfo(h_skrzynka, NULL, NULL, &lWiad, NULL);
- if (lWiad > 0) {
- CString wiadomosc;
- CFile file(h_skrzynka);
- char wiesc[1024];
- file.Read(wiesc, 1024);
- m_ekran.GetWindowTextA(wiadomosc);
- wiadomosc.AppendFormat("%s\r\n", wiesc);
- m_ekran.SetWindowTextA(wiadomosc);
- }
- CDialog::OnTimer(nIDEvent);
- }
- void CSO4LABDlg::OnBnClickedOdswiez()
- {
- CString w;
- DWORD odpowiedzRozmiar;
- if (CallNamedPipeA("\\\\.\\pipe\\sysopnp", "GET", 4, w.GetBufferSetLength(8192), 8192, &odpowiedzRozmiar, 3000)) {
- m_lista.ResetContent();
- CString temp;
- bool first = false;
- for (unsigned int i = 0; i < odpowiedzRozmiar; i++) {
- if (w[i] == '\n' || !first) {
- if (!first && w[i] == '\n') first = true;
- else if(temp.GetLength() != 0){
- m_lista.AddString(temp);
- temp.Empty();
- }
- }
- else
- temp.AppendChar(w[i]);
- }
- }
- }
- void CSO4LABDlg::OnBnClickedWyslij()
- {
- CString bufor;
- m_lista.GetWindowTextA(bufor);
- CFile skrzynka(bufor, CFile::modeWrite + CFile::shareDenyNone);
- CString wiadomosc = "KrolArtur@C64: EXCALIBUR!";
- skrzynka.Write(wiadomosc, wiadomosc.GetLength() + 1);
- skrzynka.Close();
- }
- afx_msg LRESULT CSO4LABDlg::OnWiadomosc(WPARAM n, LPARAM m)
- {
- //TODO: Odbior przeslanego kodu
- CString tekst;
- tekst.AppendFormat("WPARAM: %X LPARAM: %X", n, m);
- MessageBox(tekst, "Info", MB_OK);
- return 0;
- }
- void CSO4LABDlg::OnBnClickedZaliczamy()
- {
- CEvent zdarzenie(0, 0, "Koniec ćwiczenia", NULL);
- zdarzenie.SetEvent();
- }
- void CSO4LABDlg::OnDestroy() {
- KillTimer(1);
- CDialog:OnDestroy();
- }
- void CSO4LABDlg::OnBnClickedKoniec()
- {
- EndDialog(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement