Advertisement
lofojak

5sPP2Task2

Oct 9th, 2024
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. #define bt1_id 1
  6. #define bt2_id 2
  7. #define bt3_id 3
  8.  
  9. LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
  10. {
  11.     if (message == WM_DESTROY)
  12.         PostQuitMessage(0);
  13.     else if (message == WM_COMMAND)
  14.     {
  15.         if (LOWORD(wparam) == bt1_id)
  16.             MessageBox(0, L" Нажали 1 кнопку", L"Сообщение", MB_OK);
  17.         else if (LOWORD(wparam) == bt2_id)
  18.             MessageBox(0, L" Нажали 2 кнопку", L"Сообщение", MB_OK);
  19.         else if (LOWORD(wparam) == bt3_id)
  20.             MessageBox(0, L" Нажали 3 кнопку", L"Сообщение", MB_OK);
  21.     }
  22.     else return DefWindowProcA(hwnd, message, wparam, lparam);
  23. }
  24.  
  25. int main()
  26. {
  27.     WNDCLASSA wcl;
  28.     memset(&wcl, 0, sizeof(WNDCLASSA));
  29.     wcl.lpszClassName = "my_Window";
  30.     wcl.lpfnWndProc = WndProc;
  31.     RegisterClassA(&wcl);
  32.     HWND hwnd;
  33.     hwnd = CreateWindow(L"my_Window", L"Окошечко", WS_OVERLAPPEDWINDOW, 10, 10, 640, 480, NULL, NULL, NULL, NULL);
  34.  
  35.     MSG msg;
  36.     ShowWindow(hwnd, SW_SHOWNORMAL);
  37.  
  38.     HWND bt1 = CreateWindow(L"button", L"Кнопка1", WS_VISIBLE | WS_CHILD, 50, 10, 75, 50, hwnd, (HMENU)bt1_id, NULL, NULL);
  39.     HWND bt2 = CreateWindow(L"button", L"Кнопка2", WS_VISIBLE | WS_CHILD, 150, 10, 75, 50, hwnd, (HMENU)bt2_id, NULL, NULL);
  40.     HWND bt3 = CreateWindow(L"button", L"Кнопка3", WS_VISIBLE | WS_CHILD, 250, 10, 75, 50, hwnd, (HMENU)bt3_id, NULL, NULL);
  41.  
  42.     while (GetMessage(&msg, NULL, 0, 0))
  43.     {
  44.         TranslateMessage(&msg);
  45.         DispatchMessage(&msg);
  46.     }
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement