Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.53 KB | None | 0 0
  1. // abcdv2Dlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "abcdv2.h"
  6. #include "abcdv2Dlg.h"
  7. #include "abcdv2dlg.h"
  8. #include ".\abcdv2dlg.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #endif
  13.  
  14. volatile int przerwij;
  15. CEvent gotowea;
  16. CEvent gotoweb;
  17. CEvent gotowec;
  18. CEvent gotowed;
  19. CString ekran;
  20. // CAboutDlg dialog used for App About
  21.  
  22. class CAboutDlg : public CDialog
  23. {
  24. public:
  25.     CAboutDlg();
  26.  
  27. // Dialog Data
  28.     enum { IDD = IDD_ABOUTBOX };
  29.  
  30.     protected:
  31.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  32.  
  33. // Implementation
  34. protected:
  35.     DECLARE_MESSAGE_MAP()
  36. };
  37.  
  38. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  39. {
  40. }
  41.  
  42. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45. }
  46.  
  47. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  48. END_MESSAGE_MAP()
  49.  
  50.  
  51. // Cabcdv2Dlg dialog
  52.  
  53.  
  54.  
  55. Cabcdv2Dlg::Cabcdv2Dlg(CWnd* pParent /*=NULL*/)
  56.     : CDialog(Cabcdv2Dlg::IDD, pParent)
  57. {
  58.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60.  
  61. void Cabcdv2Dlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63.     CDialog::DoDataExchange(pDX);
  64.     DDX_Control(pDX, IDC_EDIT1, m_ekran);
  65.     DDX_Control(pDX, IDC_BUTTON2, m_uruchom);
  66.     DDX_Control(pDX, IDC_BUTTON1, m_zatrzymaj);
  67. }
  68.  
  69. BEGIN_MESSAGE_MAP(Cabcdv2Dlg, CDialog)
  70.     ON_WM_SYSCOMMAND()
  71.     ON_WM_PAINT()
  72.     ON_WM_QUERYDRAGICON()
  73.     //}}AFX_MSG_MAP
  74.     ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
  75.     ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
  76.     ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
  77. END_MESSAGE_MAP()
  78.  
  79.  
  80. // Cabcdv2Dlg message handlers
  81.  
  82. BOOL Cabcdv2Dlg::OnInitDialog()
  83. {
  84.     CDialog::OnInitDialog();
  85.  
  86.     // Add "About..." menu item to system menu.
  87.  
  88.     // IDM_ABOUTBOX must be in the system command range.
  89.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  90.     ASSERT(IDM_ABOUTBOX < 0xF000);
  91.  
  92.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  93.     if (pSysMenu != NULL)
  94.     {
  95.         CString strAboutMenu;
  96.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  97.         if (!strAboutMenu.IsEmpty())
  98.         {
  99.             pSysMenu->AppendMenu(MF_SEPARATOR);
  100.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  101.         }
  102.     }
  103.  
  104.     // Set the icon for this dialog.  The framework does this automatically
  105.     //  when the application's main window is not a dialog
  106.     SetIcon(m_hIcon, TRUE);         // Set big icon
  107.     SetIcon(m_hIcon, FALSE);        // Set small icon
  108.  
  109.     // TODO: Add extra initialization here
  110.    
  111.     return TRUE;  // return TRUE  unless you set the focus to a control
  112. }
  113.  
  114. void Cabcdv2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  115. {
  116.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  117.     {
  118.         CAboutDlg dlgAbout;
  119.         dlgAbout.DoModal();
  120.     }
  121.     else
  122.     {
  123.         CDialog::OnSysCommand(nID, lParam);
  124.     }
  125. }
  126.  
  127. // If you add a minimize button to your dialog, you will need the code below
  128. //  to draw the icon.  For MFC applications using the document/view model,
  129. //  this is automatically done for you by the framework.
  130.  
  131. void Cabcdv2Dlg::OnPaint()
  132. {
  133.     if (IsIconic())
  134.     {
  135.         CPaintDC dc(this); // device context for painting
  136.  
  137.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  138.  
  139.         // Center icon in client rectangle
  140.         int cxIcon = GetSystemMetrics(SM_CXICON);
  141.         int cyIcon = GetSystemMetrics(SM_CYICON);
  142.         CRect rect;
  143.         GetClientRect(&rect);
  144.         int x = (rect.Width() - cxIcon + 1) / 2;
  145.         int y = (rect.Height() - cyIcon + 1) / 2;
  146.  
  147.         // Draw the icon
  148.         dc.DrawIcon(x, y, m_hIcon);
  149.     }
  150.     else
  151.     {
  152.         CDialog::OnPaint();
  153.     }
  154. }
  155.  
  156. // The system calls this function to obtain the cursor to display while the user drags
  157. //  the minimized window.
  158. HCURSOR Cabcdv2Dlg::OnQueryDragIcon()
  159. {
  160.     return static_cast<HCURSOR>(m_hIcon);
  161. }
  162.  
  163. void Cabcdv2Dlg::OnBnClickedButton2()
  164. {
  165.     m_uruchom.EnableWindow(false);
  166.     m_zatrzymaj.EnableWindow();
  167.     przerwij = 0;
  168.     int i=0;
  169.     AfxBeginThread(watekac, (void *)i);
  170.     AfxBeginThread(watekbd, (void *)i);
  171.     gotowed.SetEvent();
  172. }
  173.  
  174. UINT Cabcdv2Dlg::watekac(void* lp)
  175. {
  176.  
  177.     do
  178.     {
  179.             CSingleLock sd(&gotowed);
  180.     CSingleLock sb(&gotoweb);
  181.     if(przerwij) return 0;
  182.     sd.Lock();
  183.     ekran.AppendFormat("A");
  184.     gotowea.SetEvent();
  185.     sb.Lock();
  186.     ekran.AppendFormat("C");
  187.     gotowec.SetEvent();
  188.     }
  189.     while (1);
  190.     return 0;
  191. }
  192.  
  193. UINT Cabcdv2Dlg::watekbd(void* lp)
  194. {
  195.  
  196.     do
  197.     {
  198.         CSingleLock sa(&gotowea);
  199.         CSingleLock sc(&gotowec);
  200.         if(przerwij) return 0;
  201.         sa.Lock();
  202.         ekran.AppendFormat("B");
  203.         gotoweb.SetEvent();
  204.         sc.Lock();
  205.         ekran.AppendFormat("D\r\n");
  206.             gotowed.SetEvent();
  207.     }
  208.     while (1);
  209.     return 0;
  210. }
  211. void Cabcdv2Dlg::OnBnClickedButton1()
  212. {
  213.     m_uruchom.EnableWindow();
  214.     m_zatrzymaj.EnableWindow(false);
  215.     przerwij = 1;
  216. }
  217.  
  218. void Cabcdv2Dlg::OnBnClickedButton3()
  219. {
  220.     m_ekran.SetWindowText(ekran);
  221. }
Add Comment
Please, Sign In to add comment