Advertisement
AleksandarH

(Old) PS - WDA #1

May 10th, 2022 (edited)
2,574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Revision.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "Revision.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    ProgressBar(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_REVISION, 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_REVISION));
  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_REVISION));
  78.     wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
  79.     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  80.     wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_REVISION);
  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 ID_REVISION_PROGRESSBAR:
  136.             DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, ProgressBar);
  137.             break;
  138.         default:
  139.             return DefWindowProc(hWnd, message, wParam, lParam);
  140.         }
  141.     }
  142.     break;
  143.     case WM_PAINT:
  144.     {
  145.         PAINTSTRUCT ps;
  146.         HDC hdc = BeginPaint(hWnd, &ps);
  147.         // TODO: Add any drawing code that uses hdc here...
  148.         EndPaint(hWnd, &ps);
  149.     }
  150.     break;
  151.     case WM_DESTROY:
  152.         PostQuitMessage(0);
  153.         break;
  154.     default:
  155.         return DefWindowProc(hWnd, message, wParam, lParam);
  156.     }
  157.     return 0;
  158. }
  159.  
  160. INT_PTR CALLBACK ProgressBar(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  161. {
  162.     UNREFERENCED_PARAMETER(lParam);
  163.     static int step = 1;
  164.     int temp = 0;
  165.     switch (message)
  166.     {
  167.     case WM_INITDIALOG:
  168.         SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  169.         return (INT_PTR)TRUE;
  170.  
  171.     case WM_COMMAND:
  172.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  173.         {
  174.             EndDialog(hDlg, LOWORD(wParam));
  175.             return (INT_PTR)TRUE;
  176.         }
  177.         if (LOWORD(wParam) == IDC_BUTTON1)
  178.         {
  179.             if (GetDlgItemInt(hDlg, IDC_EDIT1, NULL, FALSE) != 0)
  180.             {
  181.                 SetDlgItemText(hDlg, IDC_STATICTEXT, "False");
  182.                 SetDlgItemInt(hDlg, IDC_EDIT1, 0, FALSE);
  183.                 SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETPOS, 0, 0);
  184.                 SetTimer(hDlg, TIMER1, 20, NULL);
  185.             }
  186.             else
  187.             {
  188.                 SetTimer(hDlg, TIMER1, 20, NULL);
  189.             }
  190.         }
  191.         break;
  192.  
  193.     case WM_TIMER:
  194.         int counter = GetDlgItemInt(hDlg, IDC_EDIT1, NULL, FALSE);
  195.         counter += 1;
  196.         SetDlgItemInt(hDlg, IDC_EDIT1, counter, NULL);
  197.         if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) < 100)
  198.         {
  199.             SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETSTEP, step, 0);
  200.             SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_STEPIT, 0, 0);
  201.         }
  202.         if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) == 100)
  203.         {
  204.             SetDlgItemText(hDlg, IDC_STATICTEXT, "True");
  205.         }
  206.         if (counter == 100)
  207.         {
  208.             KillTimer(hDlg, TIMER1);
  209.         }
  210.         break;
  211.     }
  212.     return (INT_PTR)FALSE;
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement