AttackingDirectory

Untitled

Apr 28th, 2022
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. ---------
  2. Header.h
  3. --------
  4. #pragma once
  5.  
  6. #define MI_EXIT 101
  7. #define ID_OK 201
  8.  
  9. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  10. void OnCommand(HWND, int, HWND, UINT);
  11. int OnDestroy(HWND hwnd);
  12. int MakingWindow(HINSTANCE, int, int,int,int);
  13. BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  14. void DlgOnCommand(HWND, int, HWND, UINT);
  15.  
  16.  
  17. ---------
  18. Resource.rc
  19. ---------
  20. #include "winres.h"
  21. #include "Header.h"
  22. Main MENU
  23. {
  24.     POPUP "&Помощь"
  25. {
  26.         MENUITEM "&Выход", MI_EXIT;
  27. }
  28. }
  29.  
  30. ExitConfirm DIALOG 300,100,93,50
  31. STYLE WS_CAPTION | WS_POPUP | DS_MODALFRAME
  32. CAPTION "Подтвердите выход"
  33. {
  34.     CONTROL "Выход", ID_OK, "BUTTON", BS_PUSHBUTTON, 27, 32, 43, 12;
  35. }
  36.  
  37.  
  38. ----------
  39. SOURCE.CPP
  40. ----------
  41.  
  42. #include <Windows.h>
  43. #include <windowsx.h>
  44. #include "Header.h"
  45. char szClassName[] = "Main";
  46. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
  47. {
  48.     WNDCLASS wd;
  49.     ZeroMemory(&wd, sizeof(wd));
  50.     wd.lpfnWndProc = WndProc;
  51.     wd.lpszClassName = szClassName;
  52.     wd.hInstance = hInst;
  53.     wd.hCursor = LoadCursor(NULL, IDC_ARROW);
  54.     wd.lpszMenuName = "Main";
  55.     wd.hbrBackground = CreateSolidBrush(BLACK_BRUSH);
  56.     RegisterClass(&wd);
  57.     MakingWindow(hInst, 100,100,300,300);
  58. }
  59.  
  60. int MakingWindow(HINSTANCE hInst, int x,int y, int width, int height)
  61. {
  62.     HWND hwnd = CreateWindowEx(WS_EX_TOPMOST, szClassName, "Info", WS_OVERLAPPEDWINDOW, x, y, width, height, HWND_DESKTOP, NULL, hInst, NULL);
  63.     ShowWindow(hwnd, SW_SHOWNORMAL);
  64.     MSG msg;
  65.     while (GetMessage(&msg, NULL, 0, 0))
  66.     {
  67.         DispatchMessage(&msg);
  68.     }
  69.     return 0;
  70. }
  71.  
  72. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  73. {
  74.     switch (msg)
  75.     {
  76.         HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
  77.         HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
  78.     default:
  79.         return(DefWindowProc(hwnd, msg, wParam, lParam));
  80.     }
  81. }
  82. void OnCommand(HWND hwnd, int id, HWND, UINT)
  83. {
  84.     switch (id)
  85.     {
  86.     case MI_EXIT:
  87.         DialogBox((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), "ExitConfirm", NULL, DlgProc);
  88.         break;
  89.     }
  90. }
  91. int OnDestroy(HWND hwnd)
  92. {
  93.     RECT r;
  94.     GetWindowRect(hwnd, &r);
  95.     MakingWindow((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), r.left, r.top, r.right-r.left, r.bottom-r.top);
  96.     return 0;
  97. }
  98. //Обработка модального диалога ExitConfirm
  99. BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  100. {
  101.     switch (msg)
  102.     {
  103.         HANDLE_MSG(hwnd, WM_COMMAND, DlgOnCommand);
  104.     default:
  105.         return FALSE;
  106.     }
  107. }
  108. void DlgOnCommand(HWND hwnd, int id, HWND, UINT)
  109. {
  110.     switch (id)
  111.     {
  112.     case ID_OK:
  113.         MessageBeep(MB_ICONASTERISK);
  114.         EndDialog(hwnd, 0);
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment