Advertisement
lossyy

smth

Oct 12th, 2020 (edited)
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3.  
  4. #define STRICT
  5. #define WIN32_LEAN_AND_MEAN
  6.  
  7. #define CLASS  "wClass"
  8. #define OVERL  "overlaped"
  9. #define CHLD  "child"
  10. #define POPUP  "popup"
  11.  
  12. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  13.  
  14. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  15.     LPSTR lpCmdLine, int nCmdShow)
  16. {
  17.  
  18.     LPCTSTR szClass = TEXT(CLASS);
  19.  
  20.     WNDCLASS wc = { 0 };
  21.     wc.lpfnWndProc = WndProc;
  22.     wc.hInstance = hInstance;
  23.     wc.lpszClassName = szClass;
  24.     wc.style = CS_DBLCLKS;
  25.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  26.  
  27.     if (!::RegisterClass(&wc))
  28.         return -1;
  29.  
  30.     HWND wndOverlapped = ::CreateWindow(szClass, OVERL,
  31.         WS_OVERLAPPEDWINDOW,
  32.         0, 0, 500, 300, NULL, NULL, hInstance, NULL);
  33.     if (!wndOverlapped) {
  34.         return -1;
  35.     }
  36.    
  37.     HWND wndChild = ::CreateWindow(szClass, CHLD,
  38.         WS_CHILD | WS_CAPTION | WS_SYSMENU| WS_MINIMIZEBOX |
  39.         WS_MAXIMIZEBOX | WS_THICKFRAME | WS_VISIBLE,
  40.         0, 0, 200, 150, wndOverlapped, NULL, hInstance, NULL);
  41.     if (!wndChild) {
  42.         return -1;
  43.     }
  44.  
  45.     HWND wndPopup = ::CreateWindow(szClass, POPUP,
  46.         WS_POPUPWINDOW | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX |
  47.         WS_MINIMIZEBOX | WS_VISIBLE,
  48.         700, 150, 400, 200, wndOverlapped, NULL, hInstance, NULL);
  49.     if (!wndPopup) {
  50.         return -1;
  51.     }
  52.  
  53.     ::ShowWindow(wndOverlapped, nCmdShow);
  54.    
  55.     MSG msg;
  56.     while (::GetMessage(&msg, NULL, 0, 0)) {
  57.         ::DispatchMessage(&msg);
  58.     }
  59.  
  60.     return 0;
  61. }
  62.  
  63. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  64. {
  65.     switch (message) {
  66.  
  67.     case WM_LBUTTONDOWN:
  68.     {
  69.         HWND main = FindWindow(CLASS, OVERL);
  70.         HWND popup = FindWindow(CLASS, POPUP);
  71.         HWND child = FindWindowEx(main, NULL, CLASS, CHLD);
  72.         if (!child) child = FindWindowEx(popup, NULL, CLASS, CHLD);
  73.         if (!IsChild(hWnd, child) && hWnd == main)
  74.             SetParent(child, hWnd);
  75.         else if (!IsChild(hWnd, child) && hWnd == popup)
  76.             SetParent(child, hWnd);
  77.         return 0;
  78.     }
  79.  
  80.     case WM_RBUTTONDBLCLK:
  81.     {
  82.         HWND popup = FindWindow(CLASS, POPUP);
  83.         if (hWnd == popup){
  84.             if (::GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST){
  85.                 SetWindowPos(popup, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  86.             }
  87.             else {
  88.                 SetWindowPos(popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);}
  89.             }
  90.         return 0;
  91.     }
  92.    
  93.     case WM_DESTROY:
  94.         {
  95.         if (hWnd== FindWindow(CLASS, OVERL))
  96.         ::PostQuitMessage(0);
  97.         return 0;
  98.         }
  99.     }
  100.  
  101.     return ::DefWindowProc(hWnd, message, wParam, lParam);
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement