#include <windows.h>
LONG APIENTRY WndProc(HWND, UINT, WPARAM, LPARAM);
LONG APIENTRY WndProc2(HWND , UINT , WPARAM , LPARAM );
const char szWindowClass[] = "Windows";
const char szPopupWindowClass[] = "Popup";
HWND hWndPopup;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HWND hWndMain;
LPRECT rcParent;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_UPARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+10);
wc.lpszMenuName = NULL;
wc.lpszClassName = szWindowClass;
WNDCLASS wpc;
wpc.style = CS_HREDRAW | CS_VREDRAW;
wpc.lpfnWndProc = (WNDPROC)WndProc2;
wpc.cbClsExtra = 0;
wpc.cbWndExtra = 0;
wpc.hInstance = hInstance;
wpc.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
wpc.hCursor = LoadCursor(NULL,IDC_UPARROW);
wpc.hbrBackground = (HBRUSH)(COLOR_WINDOW+10);
wpc.lpszMenuName = NULL;
wpc.lpszClassName = szPopupWindowClass;
//Step1. Registering Window Class
if (!RegisterClass(&wc))
{
MessageBox(NULL, "Window Registration Failed", "Error", MB_ICONEXCLAMATION | MB_OK);
return 1;
}
if (!RegisterClass(&wpc))
{
MessageBox(NULL, "Pop-up Window Registration Failed", "Error", MB_ICONEXCLAMATION | MB_OK);
return 1;
}
//Step 2:Finding the screen size
int a,a1;
a= GetSystemMetrics(SM_CXSCREEN);
int b,b1;
b = GetSystemMetrics(SM_CYSCREEN);
a1 = a/3;
b1=b/3;
//Step 3: Creating the Window
hWndMain = CreateWindow(szWindowClass,"Main window", WS_OVERLAPPEDWINDOW,0,b-b1,a1,b1,NULL, NULL, hInstance, NULL);
if (!hWndMain)
{
MessageBox(NULL, "Window Creation Failed", "Error", MB_ICONEXCLAMATION | MB_OK);
return 2;
}
ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);
static LPRECT rcMain;
//Step 4: Create the pop-up window
hWndPopup = CreateWindow(szPopupWindowClass,"POP-UP",WS_OVERLAPPEDWINDOW|WS_POPUP,(a1- (a1/4))-24,b-b1,a1/4,b1/4,NULL,NULL,hInstance,NULL);
if (!hWndPopup)
{
MessageBox(NULL, "Pop-up Window Creation Failed", "Error", MB_ICONEXCLAMATION | MB_OK);
return 2;
}
ShowWindow(hWndPopup,SW_HIDE);
UpdateWindow(hWndPopup);
//Step 5: The Message Loop
while (GetMessage(&msg, NULL, 0, 0))
DispatchMessage(&msg);
return 0;
}
//The Window Procedure for popup-up window
LONG APIENTRY WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_RBUTTONDOWN:
{
ShowWindow(hWndPopup, SW_SHOW);
UpdateWindow (hWndPopup);
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
break;
}
case WM_RBUTTONUP:
{
ShowWindow(hWndPopup, SW_HIDE);
UpdateWindow (hWndPopup);
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
break;
}
????????????????????????????????????
case WM_LBUTTONDOWN:
{
LPRECT rcMain;
rcMain=(LPRECT)lParam;
MoveWindow(hWnd,(rcMain->right/3),0,rcMain->right/3,rcMain->bottom,TRUE);
ShowWindow(hWnd,SW_HIDE);
return TRUE;
??????????????????????????????????????
}
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//Window Procedure for main window;
HINSTANCE hInstance;
LONG APIENTRY WndProc2(HWND hWndMain, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
DestroyWindow(hWndMain);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWndMain, message, wParam, lParam);
}
return 0;
}
Перемещение pop-up окна вместе с основным
Мне нужно сделать так, чтобы при перемещении основного окна, вместе с ним перемещалось и основное окно.Pop-up полявляется при нажатие правой кнопки мышки в верхнем правом углу основного окна. Я сделала возможный правильный вариант, но не понимаю как связать основное окно с pop-up.