Advertisement
AleksandarH

(Old) PS - WDA #2

May 10th, 2022 (edited)
2,787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // testamanqk.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "testamanqk.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    grandefdini(HWND, UINT, WPARAM, LPARAM);
  21. INT_PTR CALLBACK    JTA(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_TESTAMANQK, 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_TESTAMANQK));
  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_TESTAMANQK));
  80.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  81.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  82.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_TESTAMANQK);
  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 ID_BABAJE_FORTYNAITY:
  138.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, grandefdini);
  139.                 break;
  140.             case ID_BABAJE_HIKISHIKIS:
  141.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hWnd, JTA);
  142.                 break;
  143.             case IDM_ABOUT:
  144.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  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.     char data[20];
  175.     int c_index, l_index;
  176.     int mID;
  177.     int cbIndex;
  178.     int lbIndex;
  179.     mID = LOWORD(wParam);
  180.     UNREFERENCED_PARAMETER(lParam);
  181.     switch (message)
  182.     {
  183.     case WM_INITDIALOG:
  184.         return (INT_PTR)TRUE;
  185.  
  186.     case WM_COMMAND:
  187.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  188.         {
  189.             EndDialog(hDlg, LOWORD(wParam));
  190.             return (INT_PTR)TRUE;
  191.         }
  192.         break;
  193.     }
  194.     return (INT_PTR)FALSE;
  195. }
  196. INT_PTR CALLBACK grandefdini(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  197. {
  198.     char data[20];
  199.     int c_index, l_index;
  200.     int mID;
  201.     int cbIndex;
  202.     int lbIndex;
  203.     mID = LOWORD(wParam);
  204.     UNREFERENCED_PARAMETER(lParam);
  205.     switch (message)
  206.     {
  207.     case WM_INITDIALOG: {
  208.  
  209.  
  210.         c_index = SendDlgItemMessage(hDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)"17.4");
  211.         c_index = SendDlgItemMessage(hDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)"-9.1");
  212.         // SendDlgItemMessage(hDlg, IDC_COMBO2, CB_SELECTSTRING, -1, (LPARAM)"Row 2 in Combo Box");
  213.         return (INT_PTR)TRUE;
  214.         break;
  215.     }
  216.     case WM_COMMAND:
  217.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  218.         {
  219.             EndDialog(hDlg, LOWORD(wParam));
  220.             return (INT_PTR)TRUE;
  221.         }
  222.  
  223.         else if (mID == IDC_BUTTON1) {
  224.             GetDlgItemText(hDlg, IDC_EDIT1, data, sizeof(data));
  225.  
  226.             //MessageBox(hDlg,data,"asd",MB_OK);
  227.             if (!(SendDlgItemMessage(hDlg, IDC_COMBO1, CB_FINDSTRING, 0, (LPARAM)data) > -1))
  228.             {
  229.                 c_index = SendDlgItemMessage(hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)data);
  230.                 SendDlgItemMessage(hDlg, IDC_COMBO1, CB_SETCURSEL, c_index, 0);
  231.                 MessageBox(hDlg, "added in combo box", "asd", MB_OK);
  232.             }
  233.            
  234.  
  235.             break;
  236.         }
  237.         else if (mID == IDC_BUTTON2 == 4) {
  238.  
  239.             break;
  240.         }
  241.  
  242.        
  243.    
  244.     }
  245.     return (INT_PTR)FALSE;
  246. }
  247. INT_PTR CALLBACK JTA(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  248. {
  249.     char data[20];
  250.     int c_index, l_index;
  251.     int mID;
  252.     int cbIndex;
  253.     int lbIndex;
  254.     static int step = 20;
  255.     mID = LOWORD(wParam);
  256.     UNREFERENCED_PARAMETER(lParam);
  257.     switch (message)
  258.     {
  259.     case WM_INITDIALOG:
  260.         SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
  261.         SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
  262.         SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETPOS, 0, 0);
  263.         SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETPOS, 0, 0);
  264.         return (INT_PTR)TRUE;
  265.  
  266.     case WM_COMMAND:
  267.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  268.         {
  269.             EndDialog(hDlg, LOWORD(wParam));
  270.             return (INT_PTR)TRUE;
  271.         }
  272.         if (LOWORD(wParam) == IDC_BUTTON1)
  273.         {
  274.             SetTimer(hDlg, TIMER1, 20, NULL);
  275.             break;
  276.         }
  277.         if (LOWORD(wParam) == IDC_BUTTON2)
  278.         {
  279.             KillTimer(hDlg, TIMER1);
  280.             SetDlgItemInt(hDlg, IDC_EDIT1, 0, NULL);
  281.             break;
  282.         }
  283.        
  284.         break;
  285.     case WM_TIMER: {
  286.         int counter = GetDlgItemInt(hDlg, IDC_EDIT1, NULL, FALSE);
  287.         counter += 1;
  288.         SetDlgItemInt(hDlg, IDC_EDIT1, counter, NULL);
  289.         if (IsDlgButtonChecked(hDlg, IDC_RADIO1))
  290.         {
  291.             if (SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_GETPOS, 0, 0) < 1000)
  292.             {
  293.                 SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_SETSTEP, step, 0);
  294.                 SendDlgItemMessage(hDlg, IDC_PROGRESS1, PBM_STEPIT, 0, 0);
  295.             }
  296.         }
  297.         else if (IsDlgButtonChecked(hDlg, IDC_RADIO2))
  298.         {
  299.             if (SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_GETPOS, 0, 0) < 1000)
  300.             {
  301.                 SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETSTEP, step, 0);
  302.                 SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_STEPIT, 0, 0);
  303.             }
  304.         }
  305.         if (counter == 1000)
  306.         {
  307.             KillTimer(hDlg, TIMER1);
  308.         }
  309.         break;
  310.     }
  311.     }
  312.     return (INT_PTR)FALSE;
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement