窗口size: case WM_SIZE: // main window changed size // Get the dimensions of the main window's client // area, and enumerate the child windows. Pass the // dimensions to the child windows during enumeration. GetClientRect(hWnd, &rcClient); EnumChildWindows(hWnd, EnumChildProc, (LPARAM) &rcClient); break;
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam) { LPRECT rcParent; int i, idChild; // Retrieve the child-window identifier. Use it to set the // position of the child window. idChild = GetWindowLong(hwndChild, GWL_ID);
if (idChild == ID_FIRSTCHILD) i = 0; else if (idChild == ID_SECONDCHILD) i = 1; else i = 2;
// Size and position the child window. rcParent = (LPRECT) lParam; MoveWindow(hwndChild,(rcParent->right / 3) * i,0,rcParent->right / 3, rcParent->bottom,TRUE);
// Make sure the child window is visible.
ShowWindow(hwndChild, SW_SHOW);
return TRUE; }
如果2个窗口,则中间留一点空就可以是separate。 我给你的是3个窗口全用到,改变窗口大小的代码如下:蛮麻烦的!LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT result; int idChild; switch(message) { case WM_SIZING: { WORD fwSide; LPRECT lprc;//screen fwSide = wParam; // edge of window being sized lprc = (LPRECT) lParam; // screen coordinates of drag rectangle RECT parentRc; switch (fwSide) {// 只用到一条边! case WMSZ_RIGHT:// Right edge HWND hParent=GetParent(hWnd); GetClientRect(hParent,&parentRc); int WidParent=(parentRc.right-parentRc.left); HWND hChild1=GetDlgItem(hParent,ID_FIRSTCHILD); HWND hChild2=GetDlgItem(hParent,ID_SECONDCHILD); HWND hChild3=GetDlgItem(hParent,ID_THIRDCHILD);
RECT rcChild1; GetWindowRect(hChild1,&rcChild1); RECT rcChild2; GetWindowRect(hChild2,&rcChild2); RECT rcChild3; GetWindowRect(hChild3,&rcChild3); // Retrieve the child-window identifier. Use it to set the position of the child window. idChild = GetWindowLong(hWnd, GWL_ID); if(idChild==ID_FIRSTCHILD) {// 1st's right //SetWindowPos(hChild2,0,lprc->right,0,0,0,SWP_NOSIZE | SWP_NOZORDER); int Wid1st=lprc->right-lprc->left; int Wid2nd=rcChild2.right-rcChild2.left; int Wid3rd=rcChild3.right-rcChild3.left; MoveWindow(hChild2,Wid1st,0,WidParent-Wid1st-Wid3rd,rcChild2.bottom,TRUE); OutputDebugString("1\n"); } else if (idChild==ID_SECONDCHILD) { // MoveWindow(hChild2,Wid1st,0,WidParent-Wid1st-Wid3rd,rcChild2.bottom,TRUE); int Wid1st=rcChild1.right-rcChild1.left; int Wid2nd=lprc->right-lprc->left; MoveWindow(hChild3,Wid1st+Wid2nd,0,WidParent-Wid1st-Wid2nd,rcChild3.bottom,TRUE); OutputDebugString("2\n"); } break; } } break; case WM_NCHITTEST: // {//只相应Right! switch(result = DefWindowProc(hWnd,message,wParam,lParam)) {// child no height change, no left sizing case HTLEFT:// case HTTOP:// 12 case HTTOPLEFT:// 13 case HTTOPRIGHT:// 14 case HTBOTTOM:// 15 case HTBOTTOMLEFT:// 16 case HTBOTTOMRIGHT:// 17 case HTBORDER:// 18 // OutputDebugString("HTTOPLEFT\n"); return 1; } }return result; } return DefWindowProc(hWnd,message,wParam,lParam); }
ATOM RegisterChildClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)ChildWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_W32SPILITWIN);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_W32SPILITWIN;
wcex.lpszClassName = "ChildWindowClass";
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
// return RegisterClassEx(&wcex);
}
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
//
RECT rcClient;
int i; switch (message)
{
case WM_CREATE: // creating main window
// Create three invisible child windows.
for (i = 0; i < 3; i++)
{
CreateWindowEx(WS_EX_WINDOWEDGE,"ChildWindowClass",(LPCTSTR) NULL,WS_CHILD | WS_SIZEBOX,0,0,0,0,hWnd,
(HMENU) (int) (ID_FIRSTCHILD + i),hInst, NULL);
}
break;
case WM_SIZE: // main window changed size
// Get the dimensions of the main window's client
// area, and enumerate the child windows. Pass the
// dimensions to the child windows during enumeration.
GetClientRect(hWnd, &rcClient);
EnumChildWindows(hWnd, EnumChildProc, (LPARAM) &rcClient);
break;
{
LPRECT rcParent;
int i, idChild;
// Retrieve the child-window identifier. Use it to set the
// position of the child window.
idChild = GetWindowLong(hwndChild, GWL_ID);
if (idChild == ID_FIRSTCHILD) i = 0;
else if (idChild == ID_SECONDCHILD) i = 1;
else i = 2;
// Size and position the child window.
rcParent = (LPRECT) lParam;
MoveWindow(hwndChild,(rcParent->right / 3) * i,0,rcParent->right / 3, rcParent->bottom,TRUE);
// Make sure the child window is visible.
ShowWindow(hwndChild, SW_SHOW);
return TRUE;
}
我给你的是3个窗口全用到,改变窗口大小的代码如下:蛮麻烦的!LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT result;
int idChild; switch(message)
{
case WM_SIZING:
{
WORD fwSide;
LPRECT lprc;//screen
fwSide = wParam; // edge of window being sized
lprc = (LPRECT) lParam; // screen coordinates of drag rectangle
RECT parentRc; switch (fwSide)
{// 只用到一条边!
case WMSZ_RIGHT:// Right edge
HWND hParent=GetParent(hWnd);
GetClientRect(hParent,&parentRc);
int WidParent=(parentRc.right-parentRc.left); HWND hChild1=GetDlgItem(hParent,ID_FIRSTCHILD);
HWND hChild2=GetDlgItem(hParent,ID_SECONDCHILD);
HWND hChild3=GetDlgItem(hParent,ID_THIRDCHILD);
RECT rcChild1;
GetWindowRect(hChild1,&rcChild1);
RECT rcChild2;
GetWindowRect(hChild2,&rcChild2);
RECT rcChild3;
GetWindowRect(hChild3,&rcChild3);
// Retrieve the child-window identifier. Use it to set the position of the child window.
idChild = GetWindowLong(hWnd, GWL_ID);
if(idChild==ID_FIRSTCHILD)
{// 1st's right
//SetWindowPos(hChild2,0,lprc->right,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
int Wid1st=lprc->right-lprc->left;
int Wid2nd=rcChild2.right-rcChild2.left;
int Wid3rd=rcChild3.right-rcChild3.left;
MoveWindow(hChild2,Wid1st,0,WidParent-Wid1st-Wid3rd,rcChild2.bottom,TRUE);
OutputDebugString("1\n");
}
else if (idChild==ID_SECONDCHILD)
{
// MoveWindow(hChild2,Wid1st,0,WidParent-Wid1st-Wid3rd,rcChild2.bottom,TRUE);
int Wid1st=rcChild1.right-rcChild1.left;
int Wid2nd=lprc->right-lprc->left;
MoveWindow(hChild3,Wid1st+Wid2nd,0,WidParent-Wid1st-Wid2nd,rcChild3.bottom,TRUE);
OutputDebugString("2\n");
}
break;
}
} break;
case WM_NCHITTEST: //
{//只相应Right!
switch(result = DefWindowProc(hWnd,message,wParam,lParam))
{// child no height change, no left sizing
case HTLEFT://
case HTTOP:// 12
case HTTOPLEFT:// 13
case HTTOPRIGHT:// 14
case HTBOTTOM:// 15
case HTBOTTOMLEFT:// 16
case HTBOTTOMRIGHT:// 17
case HTBORDER:// 18
// OutputDebugString("HTTOPLEFT\n");
return 1;
}
}return result;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}