Silviyaa

Untitled

Apr 21st, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.73 KB | None | 0 0
  1. // Mouse events.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "Mouse events.h"
  6. #include <CommCtrl.h>
  7.  
  8.  
  9. #define MAX_LOADSTRING 100
  10.  
  11. // Global Variables:
  12. HINSTANCE hInst;                                // current instance
  13. WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  14. WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  15.  
  16. // Forward declarations of functions included in this code module:
  17. ATOM                MyRegisterClass(HINSTANCE hInstance);
  18. BOOL                InitInstance(HINSTANCE, int);
  19. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  20. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  21. INT_PTR CALLBACK    MouseTimer(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_MOUSEEVENTS, 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_MOUSEEVENTS));
  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_MOUSEEVENTS));
  80.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  81.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  82.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_MOUSEEVENTS);
  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_MOUSEORTIME:
  141.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, MouseTimer);
  142.                 break;
  143.             case IDM_EXIT:
  144.                 DestroyWindow(hWnd);
  145.                 break;
  146.             default:
  147.                 return DefWindowProc(hWnd, message, wParam, lParam);
  148.             }
  149.         }
  150.         break;
  151.     case WM_PAINT:
  152.         {
  153.             PAINTSTRUCT ps;
  154.             HDC hdc = BeginPaint(hWnd, &ps);
  155.             // TODO: Add any drawing code that uses hdc here...
  156.             EndPaint(hWnd, &ps);
  157.         }
  158.         break;
  159.     case WM_DESTROY:
  160.         PostQuitMessage(0);
  161.         break;
  162.     default:
  163.         return DefWindowProc(hWnd, message, wParam, lParam);
  164.     }
  165.     return 0;
  166. }
  167.  
  168. // Message handler for about box.
  169. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  170. {
  171.     UNREFERENCED_PARAMETER(lParam);
  172.     switch (message)
  173.     {
  174.     case WM_INITDIALOG:
  175.         return (INT_PTR)TRUE;
  176.  
  177.     case WM_COMMAND:
  178.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  179.         {
  180.             EndDialog(hDlg, LOWORD(wParam));
  181.             return (INT_PTR)TRUE;
  182.         }
  183.         break;
  184.     }
  185.     return (INT_PTR)FALSE;
  186. }
  187.  
  188. // Message handler for about box.
  189. INT_PTR CALLBACK MauseTimer(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  190. {
  191.     UNREFERENCED_PARAMETER(lParam);
  192.     switch (message)
  193.     {
  194.     case WM_INITDIALOG:
  195.         return (INT_PTR)TRUE;
  196.  
  197.     case WM_COMMAND:
  198.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  199.         {
  200.             EndDialog(hDlg, LOWORD(wParam));
  201.             return (INT_PTR)TRUE;
  202.         }
  203.  
  204.         break;
  205.  
  206.     case WM_MOUSEMOVE: {
  207.         int xPos = LOWORD(lParam);
  208.         int yPos = HIWORD(lParam);
  209.         SetDlgItemInt(hDlg, IDC_MOUSEX, xPos, true);
  210.         SetDlgItemInt(hDlg, IDC_MOUSEY, yPos, true);
  211.         if (wParam == MK_CONTROL)
  212.         {
  213.             CheckDlgButton(hDlg, IDC_CHECK_CTRL, MF_CHECKED);
  214.         }
  215.         else
  216.         {
  217.             CheckDlgButton(hDlg, IDC_CHECK_CTRL, MF_UNCHECKED);
  218.         }
  219.         if (wParam == MK_SHIFT)
  220.         {
  221.             CheckDlgButton(hDlg, IDC_CHECK_SHIFT, MF_CHECKED);
  222.         }
  223.         else
  224.         {
  225.             CheckDlgButton(hDlg, IDC_CHECK_SHIFT, MF_UNCHECKED);
  226.         }
  227.         if (wParam == MK_RBUTTON)
  228.         {
  229.             CheckDlgButton(hDlg, IDC_CHECK_RBUTTON, MF_CHECKED);
  230.         }
  231.         else
  232.         {
  233.             CheckDlgButton(hDlg, IDC_CHECK_RBUTTON, MF_UNCHECKED);
  234.         }
  235.  
  236.  
  237.     }
  238.      break;
  239.     case WM_LBUTTONDOWN: {
  240.         int x = LOWORD(lParam);
  241.         int y = HIWORD(lParam);
  242.         SetDlgItemInt(hDlg, IDC_LBUTTONX, x, true);
  243.         SetDlgItemInt(hDlg, IDC_LBUTTONY, y, true);
  244.     }
  245.  
  246.         break;
  247.     }
  248.     return (INT_PTR)FALSE;
  249. }
  250.    
  251.  
  252.  
Advertisement
Add Comment
Please, Sign In to add comment