Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <Windows.h>
- #define STRICT
- #define WIN32_LEAN_AND_MEAN
- #define CLASS "wClass"
- #define OVERL "overlaped"
- #define CHLD "child"
- #define POPUP "popup"
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- LPCTSTR szClass = TEXT(CLASS);
- WNDCLASS wc = { 0 };
- wc.lpfnWndProc = WndProc;
- wc.hInstance = hInstance;
- wc.lpszClassName = szClass;
- wc.style = CS_DBLCLKS;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- if (!::RegisterClass(&wc))
- return -1;
- HWND wndOverlapped = ::CreateWindow(szClass, OVERL,
- WS_OVERLAPPEDWINDOW,
- 0, 0, 500, 300, NULL, NULL, hInstance, NULL);
- if (!wndOverlapped) {
- return -1;
- }
- HWND wndChild = ::CreateWindow(szClass, CHLD,
- WS_CHILD | WS_CAPTION | WS_SYSMENU| WS_MINIMIZEBOX |
- WS_MAXIMIZEBOX | WS_THICKFRAME | WS_VISIBLE,
- 0, 0, 200, 150, wndOverlapped, NULL, hInstance, NULL);
- if (!wndChild) {
- return -1;
- }
- HWND wndPopup = ::CreateWindow(szClass, POPUP,
- WS_POPUPWINDOW | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX |
- WS_MINIMIZEBOX | WS_VISIBLE,
- 700, 150, 400, 200, wndOverlapped, NULL, hInstance, NULL);
- if (!wndPopup) {
- return -1;
- }
- ::ShowWindow(wndOverlapped, nCmdShow);
- MSG msg;
- while (::GetMessage(&msg, NULL, 0, 0)) {
- ::DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message) {
- case WM_LBUTTONDOWN:
- {
- HWND main = FindWindow(CLASS, OVERL);
- HWND popup = FindWindow(CLASS, POPUP);
- HWND child = FindWindowEx(main, NULL, CLASS, CHLD);
- if (!child) child = FindWindowEx(popup, NULL, CLASS, CHLD);
- if (!IsChild(hWnd, child) && hWnd == main)
- SetParent(child, hWnd);
- else if (!IsChild(hWnd, child) && hWnd == popup)
- SetParent(child, hWnd);
- return 0;
- }
- case WM_RBUTTONDBLCLK:
- {
- HWND popup = FindWindow(CLASS, POPUP);
- if (hWnd == popup){
- if (::GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST){
- SetWindowPos(popup, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
- }
- else {
- SetWindowPos(popup, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);}
- }
- return 0;
- }
- case WM_DESTROY:
- {
- if (hWnd== FindWindow(CLASS, OVERL))
- ::PostQuitMessage(0);
- return 0;
- }
- }
- return ::DefWindowProc(hWnd, message, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement