Advertisement
AleksandarH

(Old) PS - WDA #4

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