Advertisement
AleksandarH

(Old) PS - WDA #5

May 11th, 2022 (edited)
747
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // WindowsProject1.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "WindowsProject1.h"
  6. #include <stdio.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    Dialog(HWND, UINT, WPARAM, LPARAM);
  21.  
  22. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  23.                      _In_opt_ HINSTANCE hPrevInstance,
  24.                      _In_ LPWSTR    lpCmdLine,
  25.                      _In_ int       nCmdShow)
  26. {
  27.     UNREFERENCED_PARAMETER(hPrevInstance);
  28.     UNREFERENCED_PARAMETER(lpCmdLine);
  29.  
  30.     // TODO: Place code here.
  31.  
  32.     // Initialize global strings
  33.     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  34.     LoadStringW(hInstance, IDC_WINDOWSPROJECT1, szWindowClass, MAX_LOADSTRING);
  35.     MyRegisterClass(hInstance);
  36.  
  37.     // Perform application initialization:
  38.     if (!InitInstance (hInstance, nCmdShow))
  39.     {
  40.         return FALSE;
  41.     }
  42.  
  43.     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOWSPROJECT1));
  44.  
  45.     MSG msg;
  46.  
  47.     // Main message loop:
  48.     while (GetMessage(&msg, nullptr, 0, 0))
  49.     {
  50.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  51.         {
  52.             TranslateMessage(&msg);
  53.             DispatchMessage(&msg);
  54.         }
  55.     }
  56.  
  57.     return (int) msg.wParam;
  58. }
  59.  
  60.  
  61.  
  62. //
  63. //  FUNCTION: MyRegisterClass()
  64. //
  65. //  PURPOSE: Registers the window class.
  66. //
  67. ATOM MyRegisterClass(HINSTANCE hInstance)
  68. {
  69.     WNDCLASSEXW wcex;
  70.  
  71.     wcex.cbSize = sizeof(WNDCLASSEX);
  72.  
  73.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  74.     wcex.lpfnWndProc    = WndProc;
  75.     wcex.cbClsExtra     = 0;
  76.     wcex.cbWndExtra     = 0;
  77.     wcex.hInstance      = hInstance;
  78.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT1));
  79.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  80.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  81.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_WINDOWSPROJECT1);
  82.     wcex.lpszClassName  = szWindowClass;
  83.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  84.  
  85.     return RegisterClassExW(&wcex);
  86. }
  87.  
  88. //
  89. //   FUNCTION: InitInstance(HINSTANCE, int)
  90. //
  91. //   PURPOSE: Saves instance handle and creates main window
  92. //
  93. //   COMMENTS:
  94. //
  95. //        In this function, we save the instance handle in a global variable and
  96. //        create and display the main program window.
  97. //
  98. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  99. {
  100.    hInst = hInstance; // Store instance handle in our global variable
  101.  
  102.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  103.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  104.  
  105.    if (!hWnd)
  106.    {
  107.       return FALSE;
  108.    }
  109.  
  110.    ShowWindow(hWnd, nCmdShow);
  111.    UpdateWindow(hWnd);
  112.  
  113.    return TRUE;
  114. }
  115.  
  116. //
  117. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  118. //
  119. //  PURPOSE: Processes messages for the main window.
  120. //
  121. //  WM_COMMAND  - process the application menu
  122. //  WM_PAINT    - Paint the main window
  123. //  WM_DESTROY  - post a quit message and return
  124. //
  125. //
  126. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  127. {
  128.     switch (message)
  129.     {
  130.     case WM_COMMAND:
  131.         {
  132.             int wmId = LOWORD(wParam);
  133.             // Parse the menu selections:
  134.             switch (wmId)
  135.             {
  136.             case IDM_ABOUT:
  137.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  138.                 break;
  139.             case IDM_EXIT:
  140.                 DestroyWindow(hWnd);
  141.                 break;
  142.             case ID_DIALOG_DIALOG:
  143.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, Dialog);
  144.                 break;
  145.             default:
  146.                 return DefWindowProc(hWnd, message, wParam, lParam);
  147.             }
  148.         }
  149.         break;
  150.     case WM_PAINT:
  151.         {
  152.             PAINTSTRUCT ps;
  153.             HDC hdc = BeginPaint(hWnd, &ps);
  154.             // TODO: Add any drawing code that uses hdc here...
  155.             EndPaint(hWnd, &ps);
  156.         }
  157.         break;
  158.     case WM_DESTROY:
  159.         PostQuitMessage(0);
  160.         break;
  161.     default:
  162.         return DefWindowProc(hWnd, message, wParam, lParam);
  163.     }
  164.     return 0;
  165. }
  166.  
  167. // Message handler for about box.
  168. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  169. {
  170.     UNREFERENCED_PARAMETER(lParam);
  171.     switch (message)
  172.     {
  173.     case WM_INITDIALOG:
  174.         return (INT_PTR)TRUE;
  175.  
  176.     case WM_COMMAND:
  177.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  178.         {
  179.             EndDialog(hDlg, LOWORD(wParam));
  180.             return (INT_PTR)TRUE;
  181.         }
  182.         break;
  183.     }
  184.     return (INT_PTR)FALSE;
  185. }
  186.  
  187.  
  188. INT_PTR CALLBACK Dialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  189. {
  190.     UNREFERENCED_PARAMETER(lParam);
  191.     char data[100];
  192.     int c_index;
  193.     switch (message)
  194.     {
  195.     case WM_INITDIALOG:
  196.         c_index = SendDlgItemMessage(hDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)"17.4");
  197.         c_index = SendDlgItemMessage(hDlg, IDC_COMBO2, CB_ADDSTRING, 0, (LPARAM)"-9.1");
  198.         return (INT_PTR)TRUE;
  199.  
  200.     case WM_COMMAND:
  201.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  202.         {
  203.             EndDialog(hDlg, LOWORD(wParam));
  204.             return (INT_PTR)TRUE;
  205.         }
  206.         else if (LOWORD(wParam) == IDC_BUTTON1)
  207.         {
  208.             GetDlgItemText(hDlg, IDC_EDIT1, data, sizeof(data));
  209.             if (!(SendDlgItemMessage(hDlg, IDC_COMBO1, CB_FINDSTRING, 0, (LPARAM)data) > -1))
  210.             {
  211.                 c_index = SendDlgItemMessage(hDlg, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)data);
  212.                 SendDlgItemMessage(hDlg, IDC_COMBO1, CB_SETCURSEL, c_index, 0);
  213.             }
  214.         }
  215.         else if (LOWORD(wParam) == IDC_BUTTON2)
  216.         {
  217.             BOOL* LPt = NULL;
  218.             BOOL SIG = TRUE;
  219.             double a = 0, b = 0, c = 0;
  220.             double result = 0;
  221.             if (IsDlgButtonChecked(hDlg, IDC_CHECK1))
  222.             {
  223.                 a = GetDlgItemInt(hDlg, IDC_EDIT2, LPt, SIG);
  224.             }
  225.             if (IsDlgButtonChecked(hDlg, IDC_CHECK2))
  226.             {
  227.                 b = GetDlgItemInt(hDlg, IDC_EDIT3, LPt, SIG);
  228.             }
  229.             if (IsDlgButtonChecked(hDlg, IDC_CHECK3))
  230.             {
  231.  
  232.             }
  233.             result = c + b - a;
  234.             SetDlgItemInt(hDlg, IDC_EDIT4, result, SIG);
  235.         }
  236.         break;
  237.     }
  238.     return (INT_PTR)FALSE;
  239. }
  240.  
Advertisement
RAW Paste Data Copied
Advertisement