C++ Win32-子窗口绘制
我有一个主窗口,其中包含两个子窗口(Child1和Child2)。将Child2移动到Child1的顶部,然后将Child1移开,将Child2客户端区域和非客户端区域绘制到Child1上 如图所示: 需要帮忙吗C++ Win32-子窗口绘制,c++,windows,winapi,C++,Windows,Winapi,我有一个主窗口,其中包含两个子窗口(Child1和Child2)。将Child2移动到Child1的顶部,然后将Child1移开,将Child2客户端区域和非客户端区域绘制到Child1上 如图所示: 需要帮忙吗 #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndChildProc1(HWND, UINT, WPARAM, LPARAM); L
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndChildProc1(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndChildProc2(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{
WNDCLASS wndclass;
HWND hwndMain, hwndChild1, hwndChild2;
MSG msg;
//register main window class
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = 0;
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
wndclass.hInstance = hInstance;
wndclass.hbrBackground = (HBRUSH) COLOR_WINDOW;
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = TEXT("MainWindow");
if(!RegisterClass(&wndclass)) return 0;
//register child window class
wndclass.lpfnWndProc = WndChildProc1;
wndclass.lpszClassName = TEXT("ChildWindow1");
if(!RegisterClass(&wndclass)) return 0;
wndclass.lpfnWndProc = WndChildProc2;
wndclass.lpszClassName = TEXT("ChildWindow2");
if(!RegisterClass(&wndclass)) return 0;
//create main window
hwndMain = CreateWindow(TEXT("MainWindow"), TEXT("Main Window"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
0, 0, hInstance, 0);
if(!hwndMain) return 0;
//create child windows
hwndChild1 = CreateWindow(TEXT("ChildWindow1"), TEXT("Child Window 1"),
WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
10, 10, 200, 300,
hwndMain, 0, hInstance, 0);
hwndChild2 = CreateWindow(TEXT("ChildWindow2"), TEXT("Child Window 2"),
WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,
250, 10, 200, 300,
hwndMain, 0, hInstance, 0);
ShowWindow(hwndMain, SW_SHOW);
UpdateWindow(hwndMain);
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK WndChildProc1(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK WndChildProc2(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}
#包括
LRESULT回调WndProc(HWND、UINT、WPARAM、LPARAM);
LRESULT回调WndChildProc1(HWND、UINT、WPARAM、LPARAM);
LRESULT回调WndChildProc2(HWND、UINT、WPARAM、LPARAM);
int WINAPI WinMain(HINSTANCE HINSTANCE、HINSTANCE hPrevInstance、LPSTR szCmdLine、int nCmdShow)
{
WNDCLASS WNDCLASS;
HWND hwndMain、hwndChild1、hwndChild2;
味精;
//注册主窗口类
wndclass.style=CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hIcon=0;
wndclass.hCursor=LoadCursor(0,IDC_箭头);
wndclass.hInstance=hInstance;
wndclass.hbrBackground=(HBRUSH)颜色窗口;
wndclass.lpszMenuName=0;
wndclass.lpszClassName=文本(“主窗口”);
如果(!RegisterClass(&wndclass))返回0;
//注册子窗口类
wndclass.lpfnWndProc=WndChildProc1;
wndclass.lpszClassName=文本(“ChildWindow1”);
如果(!RegisterClass(&wndclass))返回0;
wndclass.lpfnWndProc=WndChildProc2;
wndclass.lpszClassName=文本(“ChildWindow2”);
如果(!RegisterClass(&wndclass))返回0;
//创建主窗口
hwndMain=CreateWindow(文本(“主窗口”)、文本(“主窗口”),
WS_重叠窗口,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
0,0,0);
如果(!hwndMain)返回0;
//创建子窗口
hwndChild1=创建窗口(文本(“子窗口1”)、文本(“子窗口1”),
WS|u CHILD | WS|u CAPTION | WS|u SYSMENU | WS|u VISIBLE,
10, 10, 200, 300,
hwndMain,0,hInstance,0);
hwndChild2=创建窗口(文本(“子窗口2”)、文本(“子窗口2”),
WS|u CHILD | WS|u CAPTION | WS|u SYSMENU | WS|u VISIBLE,
250, 10, 200, 300,
hwndMain,0,hInstance,0);
展示窗口(hwndMain、SW_SHOW);
更新域(hwndMain);
while(GetMessage(&msg,0,0,0))
{
翻译信息(&msg);
发送消息(&msg);
}
返回msg.wParam;
}
LRESULT回调WndProc(HWND HWND,UINT msg,WPARAM WPARAM,LPARAM LPARAM)
{
开关(msg)
{
案例WM_销毁:
PostQuitMessage(0);
返回0;
}
返回DefWindowProc(hwnd、msg、wParam、lParam);
}
LRESULT回调WndChildProc1(HWND HWND,UINT msg,WPARAM WPARAM,LPARAM LPARAM)
{
返回DefWindowProc(hwnd、msg、wParam、lParam);
}
LRESULT回调WndChildProc2(HWND HWND,UINT msg,WPARAM WPARAM,LPARAM LPARAM)
{
返回DefWindowProc(hwnd、msg、wParam、lParam);
}
谢谢。试试
WS\u CLIPSIBLINGS
。你想让MDI客户端窗口打开吗?谢谢-WS\u CLIPSIBLINGS可以工作。