Advertisement
Alan468

Stoper WORKING

Nov 29th, 2016
112
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;
  8. HWND _TEXT;
  9. clock_t timeStart, timeEnd;
  10.  
  11. string TimeText(int MS) {
  12.     return to_string((MS / 3600000)) + ":" + to_string((MS / 60000) - ((MS / 3600000) * 60)) + ":" +
  13.         to_string((MS / 1000) - ((MS / 60000) * 60)) + ":" + to_string(MS - ((MS / 1000) * 1000));
  14. }
  15.  
  16. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  17.     switch (msg) {
  18.     case WM_TIMER:
  19.         if (bStart) {
  20.             SetWindowText(_TEXT, TimeText(clock() - timeStart).c_str());
  21.         }
  22.         else {
  23.             SetWindowText(_TEXT, TimeText(timeEnd - timeStart).c_str());
  24.         }
  25.         break;
  26.     case WM_COMMAND:
  27.         switch (wParam) {
  28.         case 100:
  29.             if (!bStart) {
  30.                 timeStart = clock();
  31.                 bStart = true;
  32.             }
  33.             break;
  34.         case 101:
  35.             if (bStart) {
  36.                 timeEnd = clock();
  37.                 bStart = false;
  38.             }
  39.             break;
  40.         }
  41.         break;
  42.     case WM_CLOSE:
  43.         DestroyWindow(hwnd);
  44.         break;
  45.     case WM_DESTROY:
  46.         PostQuitMessage(0);
  47.         break;
  48.     default:
  49.         return DefWindowProc(hwnd, msg, wParam, lParam);
  50.         break;
  51.     }
  52.     return 0;
  53. }
  54.  
  55. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
  56.     WNDCLASSEX window;
  57.     MSG msg;
  58.     TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
  59.     window.cbClsExtra = NULL;
  60.     window.cbSize = sizeof(WNDCLASSEX);
  61.     window.cbWndExtra = NULL;
  62.     window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  63.     window.hCursor = LoadCursor(NULL, IDC_HAND);
  64.     window.hIcon = LoadIcon(NULL, IDI_INFORMATION);
  65.     window.hIconSm = NULL;
  66.     window.hInstance = hInstance;
  67.     window.lpfnWndProc = WndProc;
  68.     window.lpszClassName = Class_Name;
  69.     window.lpszMenuName = 0;
  70.     window.style = CS_VREDRAW | CS_HREDRAW;
  71.     RegisterClassEx(&window);
  72.  
  73.     HWND hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
  74.  
  75.     ShowWindow(hwnd, nCmdShow);
  76.     UpdateWindow(hwnd);
  77.  
  78.     HWND _START = CreateWindowEx(0, "BUTTON", "Start", WS_CHILD | WS_VISIBLE, 10, 10, 150, 30, hwnd, (HMENU)100, hInstance, NULL);
  79.     HWND _STOP = CreateWindowEx(0, "BUTTON", "Stop", WS_CHILD | WS_VISIBLE, 10, 45, 150, 30, hwnd, (HMENU)101, hInstance, NULL);
  80.     _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);
  81.     SendMessage(_TEXT, WM_SETFONT, (WPARAM)CreateFont(35, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Courier New")), 0);
  82.  
  83.     SetTimer(hwnd, NULL, 20, NULL);
  84.  
  85.     while (GetMessage(&msg, NULL, 0, 0)) {
  86.         TranslateMessage(&msg);
  87.         DispatchMessage(&msg);
  88.     }
  89.  
  90.     UnregisterClass(Class_Name, hInstance);
  91.     return msg.wParam;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement