Advertisement
Alan468

PIU Stoper

Nov 30th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <time.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool bStart = false, bPauze = false;
  8. HWND _TEXT;
  9. clock_t timeStart, timeEnd;
  10. HWND _START, _STOP, _SUBTIME;
  11.  
  12. string TimeText(int MS) {
  13.     return to_string((MS / 3600000)) + ":" + to_string((MS / 60000) - ((MS / 3600000) * 60)) + ":" +
  14.         to_string((MS / 1000) - ((MS / 60000) * 60)) + ":" + to_string(MS - ((MS / 1000) * 1000));
  15. }
  16.  
  17. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  18.     switch (msg) {
  19.     case WM_TIMER:
  20.         if (bStart && !bPauze)
  21.             timeEnd = clock();
  22.         SetWindowText(_TEXT, TimeText(timeEnd - timeStart).c_str());
  23.         break;
  24.  
  25.     case WM_COMMAND:
  26.         switch (wParam) {
  27.         case 100:
  28.             if (!bStart) {
  29.                 timeStart = clock();
  30.                 bStart = true;
  31.                 SetWindowText(_START, "Stop");
  32.                 EnableWindow(_STOP,1);
  33.                 EnableWindow(_SUBTIME, 1);
  34.             }
  35.             else if (bStart) {
  36.                 bStart = false;
  37.                 SetWindowText(_START, "Start");
  38.  
  39.                 EnableWindow(_SUBTIME, 0);
  40.                 EnableWindow(_STOP, 0);
  41.             }
  42.             break;
  43.         case 101:
  44.             if (!bPauze) {
  45.                 bPauze = true;
  46.                 SetWindowText(_STOP, "Wznów");
  47.                 EnableWindow(_START, 0);
  48.                 EnableWindow(_SUBTIME, 0);
  49.             }
  50.             else if (bPauze) {
  51.                 bPauze = false;
  52.                 SetWindowText(_STOP, "Pauza");
  53.                 EnableWindow(_START, 1);
  54.                 EnableWindow(_SUBTIME, 1);
  55.             }
  56.             break;
  57.         case 102:{ Sleep(2000); } break;
  58.  
  59.         }
  60.         break;
  61.     case WM_CLOSE:
  62.         DestroyWindow(hwnd);
  63.         break;
  64.     case WM_DESTROY:
  65.         PostQuitMessage(0);
  66.         break;
  67.     default:
  68.         return DefWindowProc(hwnd, msg, wParam, lParam);
  69.         break;
  70.     }
  71.     return 0;
  72. }
  73.  
  74. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
  75.     WNDCLASSEX window;
  76.     MSG msg;
  77.     TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
  78.     window.cbClsExtra = NULL;
  79.     window.cbSize = sizeof(WNDCLASSEX);
  80.     window.cbWndExtra = NULL;
  81.     window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  82.     window.hCursor = LoadCursor(NULL, IDC_HAND);
  83.     window.hIcon = LoadIcon(NULL, IDI_INFORMATION);
  84.     window.hIconSm = NULL;
  85.     window.hInstance = hInstance;
  86.     window.lpfnWndProc = WndProc;
  87.     window.lpszClassName = Class_Name;
  88.     window.lpszMenuName = 0;
  89.     window.style = CS_VREDRAW | CS_HREDRAW;
  90.     RegisterClassEx(&window);
  91.  
  92.     HWND hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
  93.  
  94.     ShowWindow(hwnd, nCmdShow);
  95.     UpdateWindow(hwnd);
  96.  
  97.     _START = CreateWindowEx(0, "BUTTON", "Start", WS_CHILD | WS_VISIBLE, 10, 10, 150, 30, hwnd, (HMENU)100, hInstance, NULL);
  98.     _STOP = CreateWindowEx(0, "BUTTON", "Pauza", WS_CHILD | WS_VISIBLE, 10, 45, 150, 30, hwnd, (HMENU)101, hInstance, NULL);
  99.     _SUBTIME = CreateWindowEx(0, "BUTTON", "Miedzyczas", WS_CHILD | WS_VISIBLE, 10, 80, 150, 30, hwnd, (HMENU)102, hInstance, NULL);
  100.     _TEXT = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_DISABLED | ES_MULTILINE | ES_AUTOVSCROLL, 165, 10, 200, 65, hwnd, (HMENU)102, hInstance, NULL);
  101.  
  102.     SetTimer(hwnd, NULL, 20, NULL);
  103.  
  104.     while (GetMessage(&msg, NULL, 0, 0)) {
  105.         TranslateMessage(&msg);
  106.         DispatchMessage(&msg);
  107.     }
  108.  
  109.     UnregisterClass(Class_Name, hInstance);
  110.     return msg.wParam;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement