AleksandarH

(Old) PS - WDA #3

May 10th, 2022 (edited)
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // test5.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "test5.h"
  6. #include "commctrl.h"
  7. #define MAX_LOADSTRING 100
  8.  
  9. // Global Variables:
  10. HINSTANCE hInst;                                // current instance
  11. WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  12. WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  13.  
  14. // Forward declarations of functions included in this code module:
  15. ATOM                MyRegisterClass(HINSTANCE hInstance);
  16. BOOL                InitInstance(HINSTANCE, int);
  17. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  18. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  19. INT_PTR CALLBACK    time(HWND, UINT, WPARAM, LPARAM);
  20.  
  21. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  22.                      _In_opt_ HINSTANCE hPrevInstance,
  23.                      _In_ LPWSTR    lpCmdLine,
  24.                      _In_ int       nCmdShow)
  25. {
  26.     UNREFERENCED_PARAMETER(hPrevInstance);
  27.     UNREFERENCED_PARAMETER(lpCmdLine);
  28.  
  29.     // TODO: Place code here.
  30.  
  31.     // Initialize global strings
  32.     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  33.     LoadStringW(hInstance, IDC_TEST5, szWindowClass, MAX_LOADSTRING);
  34.     MyRegisterClass(hInstance);
  35.  
  36.     // Perform application initialization:
  37.     if (!InitInstance (hInstance, nCmdShow))
  38.     {
  39.         return FALSE;
  40.     }
  41.  
  42.     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TEST5));
  43.  
  44.     MSG msg;
  45.  
  46.     // Main message loop:
  47.     while (GetMessage(&msg, nullptr, 0, 0))
  48.     {
  49.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  50.         {
  51.             TranslateMessage(&msg);
  52.             DispatchMessage(&msg);
  53.         }
  54.     }
  55.  
  56.     return (int) msg.wParam;
  57. }
  58.  
  59.  
  60.  
  61. //
  62. //  FUNCTION: MyRegisterClass()
  63. //
  64. //  PURPOSE: Registers the window class.
  65. //
  66. ATOM MyRegisterClass(HINSTANCE hInstance)
  67. {
  68.     WNDCLASSEXW wcex;
  69.  
  70.     wcex.cbSize = sizeof(WNDCLASSEX);
  71.  
  72.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  73.     wcex.lpfnWndProc    = WndProc;
  74.     wcex.cbClsExtra     = 0;
  75.     wcex.cbWndExtra     = 0;
  76.     wcex.hInstance      = hInstance;
  77.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST5));
  78.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  79.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  80.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_TEST5);
  81.     wcex.lpszClassName  = szWindowClass;
  82.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  83.  
  84.     return RegisterClassExW(&wcex);
  85. }
  86.  
  87. //
  88. //   FUNCTION: InitInstance(HINSTANCE, int)
  89. //
  90. //   PURPOSE: Saves instance handle and creates main window
  91. //
  92. //   COMMENTS:
  93. //
  94. //        In this function, we save the instance handle in a global variable and
  95. //        create and display the main program window.
  96. //
  97. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  98. {
  99.    hInst = hInstance; // Store instance handle in our global variable
  100.  
  101.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  102.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  103.  
  104.    if (!hWnd)
  105.    {
  106.       return FALSE;
  107.    }
  108.  
  109.    ShowWindow(hWnd, nCmdShow);
  110.    UpdateWindow(hWnd);
  111.  
  112.    return TRUE;
  113. }
  114.  
  115. //
  116. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  117. //
  118. //  PURPOSE: Processes messages for the main window.
  119. //
  120. //  WM_COMMAND  - process the application menu
  121. //  WM_PAINT    - Paint the main window
  122. //  WM_DESTROY  - post a quit message and return
  123. //
  124. //
  125. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  126. {
  127.     switch (message)
  128.     {
  129.     case WM_COMMAND:
  130.         {
  131.             int wmId = LOWORD(wParam);
  132.             // Parse the menu selections:
  133.             switch (wmId)
  134.             {
  135.             case IDM_ABOUT:
  136.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  137.                 break;
  138.             case ID_MAIKATI_TIMER:
  139.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, time);
  140.                 break;
  141.             case IDM_EXIT:
  142.                 DestroyWindow(hWnd);
  143.                 break;
  144.             default:
  145.                 return DefWindowProc(hWnd, message, wParam, lParam);
  146.             }
  147.         }
  148.         break;
  149.     case WM_PAINT:
  150.         {
  151.             PAINTSTRUCT ps;
  152.             HDC hdc = BeginPaint(hWnd, &ps);
  153.             // TODO: Add any drawing code that uses hdc here...
  154.             EndPaint(hWnd, &ps);
  155.         }
  156.         break;
  157.     case WM_DESTROY:
  158.         PostQuitMessage(0);
  159.         break;
  160.     default:
  161.         return DefWindowProc(hWnd, message, wParam, lParam);
  162.     }
  163.     return 0;
  164. }
  165.  
  166. // Message handler for about box.
  167. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  168. {
  169.     UNREFERENCED_PARAMETER(lParam);
  170.     switch (message)
  171.     {
  172.     case WM_INITDIALOG:
  173.         return (INT_PTR)TRUE;
  174.  
  175.     case WM_COMMAND:
  176.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  177.         {
  178.             EndDialog(hDlg, LOWORD(wParam));
  179.             return (INT_PTR)TRUE;
  180.         }
  181.         break;
  182.     }
  183.     return (INT_PTR)FALSE;
  184. }
  185. INT_PTR CALLBACK time(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  186. {
  187.     char data[20];
  188.     int c_index, l_index;
  189.     int mID;
  190.     int cbIndex;
  191.     int lbIndex;
  192.     int counter = 0;
  193.     static int step = 5;
  194.     mID = LOWORD(wParam);
  195.     UNREFERENCED_PARAMETER(lParam);
  196.     switch (message)
  197.     {
  198.     case WM_INITDIALOG:
  199.         SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  200.         SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  201.         SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETPOS, 0, 0);
  202.         SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETPOS, 0, 0);
  203.         return (INT_PTR)TRUE;
  204.  
  205.     case WM_COMMAND:
  206.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  207.         {
  208.             EndDialog(hDlg, LOWORD(wParam));
  209.             return (INT_PTR)TRUE;
  210.         }
  211.         if (LOWORD(wParam) == IDC_BUTTON1)
  212.         {
  213.             SetTimer(hDlg, TIMER1, 20, NULL);
  214.             break;
  215.         }
  216.         if (LOWORD(wParam) == IDC_BUTTON2)
  217.         {
  218.             KillTimer(hDlg, TIMER1);
  219.            
  220.             break;
  221.         }
  222.  
  223.         break;
  224.     case WM_TIMER: {
  225.        
  226.         counter += 1;
  227.        
  228.         if (IsDlgButtonChecked(hDlg, IDC_RADIO1))
  229.         {
  230.             if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) < 100)
  231.             {
  232.                 SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETSTEP, step, 0);
  233.                 SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_STEPIT, 0, 0);
  234.             }
  235.             if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) == 100)
  236.             {
  237.                 KillTimer(hDlg, TIMER1);
  238.                 int msgBox = MessageBox(hDlg, "Da spre li taimera?", "Timer", MB_YESNO);
  239.                 switch (msgBox)
  240.                 {
  241.                 case IDYES:
  242.                     while (1 > 0)
  243.                     {
  244.                         if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) < 100)
  245.                         {
  246.                             SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETSTEP, step, 0);
  247.                             SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_STEPIT, 0, 0);
  248.                         }
  249.                         else if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) == 100)
  250.                         {
  251.                             SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETPOS, 0, 0);
  252.                         }
  253.                     }
  254.                     break;
  255.                 case IDNO:
  256.                     break;
  257.                 }
  258.                 return msgBox;
  259.             }
  260.         }
  261.         else if (IsDlgButtonChecked(hDlg, IDC_RADIO2))
  262.         {
  263.             if (SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_GETPOS, 0, 0) < 100)
  264.             {
  265.                 SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETSTEP, step, 0);
  266.                 SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_STEPIT, 0, 0);
  267.             }
  268.             else if (SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_GETPOS, 0, 0) == 100)
  269.             {
  270.                 SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETPOS, 0, 0);
  271.             }
  272.         }
  273.         if (counter == 1000)
  274.         {
  275.             KillTimer(hDlg, TIMER1);
  276.         }
  277.         break;
  278.     }
  279.     }
  280.     return (INT_PTR)FALSE;
  281. }
Add Comment
Please, Sign In to add comment