AleksandarH

PS - Niki Code

Jun 1st, 2022 (edited)
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MishoSmells.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "MishoSmells.h"
  6. #include <commctrl.h>
  7. #include <stdio.h>
  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    Calculator(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_MISHOSMELLS, 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_MISHOSMELLS));
  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_MISHOSMELLS));
  79.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  80.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  81.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_MISHOSMELLS);
  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_MENU_K1:
  143.         {
  144.             HMENU hMenu = GetMenu(hWnd);
  145.             if (GetMenuState(hMenu, ID_MSI_K6 + 1, MF_BYCOMMAND) == -1)
  146.             {
  147.                 MENUITEMINFO mii;
  148.                 ZeroMemory(&mii, sizeof(mii));
  149.                 mii.cbSize = sizeof(mii);
  150.                 mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
  151.                 mii.wID = ID_MSI_K6 + 1;
  152.                 mii.fType = MFT_STRING;
  153.                 mii.dwTypeData = const_cast<char*>("K4");
  154.                 mii.fState = MFS_ENABLED;
  155.                 InsertMenuItem(hMenu, ID_MENU_K3, FALSE, &mii);
  156.             }
  157.             break;
  158.         }
  159.         case ID_MENU_K2:
  160.         {
  161.             HMENU hMenu = GetMenu(hWnd);
  162.             DeleteMenu(hMenu, ID_MENU_K5, MF_BYCOMMAND);
  163.             break;
  164.         }
  165.         case ID_MENU_K3:
  166.         {
  167.             HMENU hMenu = GetMenu(hWnd);
  168.             UINT res = GetMenuState(hMenu, ID_MENU_K9, MF_BYCOMMAND);
  169.             if (res & MF_DISABLED)
  170.             {
  171.                 EnableMenuItem(hMenu, ID_MENU_K9, MF_BYCOMMAND | MF_ENABLED);
  172.             }
  173.             else
  174.             {
  175.                 EnableMenuItem(hMenu, ID_MENU_K9, MF_BYCOMMAND | MF_DISABLED);
  176.             }
  177.             break;
  178.         }
  179.         case ID_MSI_K6:
  180.  
  181.             MessageBox(hWnd, "K6", "K6", MB_OK);
  182.             break;
  183.  
  184.         case ID_MENU_K9:
  185.  
  186.             MessageBox(hWnd, "K9", "Putka ti lelina", MB_OK);
  187.             break;
  188.  
  189.         case ID_MSI_K6 + 1:
  190.         {
  191.             DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, Calculator);
  192.             break;
  193.         }
  194.         default:
  195.             return DefWindowProc(hWnd, message, wParam, lParam);
  196.         }
  197.     }
  198.     break;
  199.  
  200.     case WM_RBUTTONDOWN:
  201.     {
  202.     HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1));
  203.     HMENU hSubMenu = GetSubMenu(hMenu, 0);
  204.     POINT pt = { LOWORD(lParam), HIWORD(lParam) };
  205.     ClientToScreen(hWnd, &pt);
  206.     TrackPopupMenu(hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
  207.     DestroyMenu(hMenu);
  208.     }
  209.     break;
  210.     case WM_PAINT:
  211.         {
  212.             PAINTSTRUCT ps;
  213.             HDC hdc = BeginPaint(hWnd, &ps);
  214.             // TODO: Add any drawing code that uses hdc here...
  215.             EndPaint(hWnd, &ps);
  216.         }
  217.         break;
  218.     case WM_DESTROY:
  219.         PostQuitMessage(0);
  220.         break;
  221.     default:
  222.         return DefWindowProc(hWnd, message, wParam, lParam);
  223.     }
  224.     return 0;
  225. }
  226.  
  227. // Message handler for about box.
  228. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  229. {
  230.     UNREFERENCED_PARAMETER(lParam);
  231.     switch (message)
  232.     {
  233.     case WM_INITDIALOG:
  234.         return (INT_PTR)TRUE;
  235.  
  236.     case WM_COMMAND:
  237.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  238.         {
  239.             EndDialog(hDlg, LOWORD(wParam));
  240.             return (INT_PTR)TRUE;
  241.         }
  242.         break;
  243.     }
  244.     return (INT_PTR)FALSE;
  245. }
  246. INT_PTR CALLBACK Calculator(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  247. {
  248.     char data[100],*stopstring,result[100];
  249.     double a = 0, b = 0, c = 0,d=0,e=0, math = 0;
  250.     BOOL* LPt = NULL;
  251.     BOOL SIG = TRUE;
  252.     UNREFERENCED_PARAMETER(lParam);
  253.     switch (message)
  254.     {
  255.     case WM_INITDIALOG:
  256.         CheckDlgButton(hDlg, IDC_RADIO1, BST_CHECKED);
  257.         return (INT_PTR)TRUE;
  258.  
  259.     case WM_COMMAND:
  260.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  261.         {
  262.             EndDialog(hDlg, LOWORD(wParam));
  263.             return (INT_PTR)TRUE;
  264.         }
  265.         else if(LOWORD(wParam) == IDC_BUTTON1)
  266.         {
  267.             a = GetDlgItemInt(hDlg, IDC_EDIT1, LPt, SIG);
  268.             b = GetDlgItemInt(hDlg, IDC_EDIT2, LPt, SIG);
  269.             SetDlgItemInt(hDlg, IDC_EDIT3, a * b, SIG);
  270.         }
  271.         else if (LOWORD(wParam) == IDC_BUTTON2)
  272.         {
  273.             GetDlgItemText(hDlg, IDC_EDIT4, data, sizeof(data));
  274.             c = strtod(data, &stopstring);
  275.             if (GetDlgItemInt(hDlg,IDC_EDIT5,LPt,SIG) == 0)
  276.             {
  277.                 MessageBox(hDlg, "ERROR: Cannot multiply by 0", "Misho Lqgai si", MB_OK | MB_ICONWARNING );
  278.                 break;
  279.             }
  280.             else
  281.             {
  282.                 GetDlgItemText(hDlg, IDC_EDIT5, data, sizeof(data));
  283.                 d = strtod(data, &stopstring);
  284.             }
  285.             GetDlgItemText(hDlg, IDC_EDIT6, data, sizeof(data));
  286.             e = strtod(data, &stopstring);
  287.             if (IsDlgButtonChecked(hDlg, IDC_RADIO1))
  288.             {
  289.                
  290.                 math = c - (d * e);
  291.                 sprintf_s(result, "%6.3f", math);
  292.                 SetDlgItemText(hDlg, IDC_EDIT7, result);
  293.             }
  294.             else if (IsDlgButtonChecked(hDlg, IDC_RADIO2))
  295.             {
  296.                
  297.                 math = (c*d) + e;
  298.                 sprintf_s(result, "%6.3f", math);
  299.                 SetDlgItemText(hDlg, IDC_EDIT7, result);
  300.             }
  301.  
  302.         }
  303.         break;
  304.     }
  305.     return (INT_PTR)FALSE;
  306. }
Add Comment
Please, Sign In to add comment