자식 창을 사용 하 여 서로 다른 기능 영역에는 창 클라이언트 영역을 나눌 수 있습니다. 주 창 만들기는 자식 창 만들기- CreateWindowEx 함수를 사용 합니다. 응용 프로그램 정의 창 클래스의 창을 만들려면 창 클래스를 등록 하 고 자식 창 만들기 전에 창 프로시저를 제공 해야 합니다. 자식 창 WS_CHILD 스타일이 제공 하 고 만들 때 자식 창에 대 한 부모 창 지정 해야.
다음 예제에서는 동일한 크기의 세 가지 자식 창을 생성 하 여 세 개의 기능 영역으로 응용 프로그램 창의 클라이언트 영역을 나눕니다. 각 자식 창을 주 창의 클라이언트 영역 높이 하지만 각각 1 / 3의 너비입니다. 메인 윈도우 창을 주 창의 자체 창 생성 프로세스 동안 받는 WM_CREATE 메시지에 자식을 만듭니다. 때문에 각 자식 창 WS_BORDER 스타일, 마다가 선 테두리. 또한, WS_VISIBLE 스타일 지정 되어 있지 않으므로 각 자식 창은 처음에 숨겨져 있습니다. 또한 각 자식 창의 자식 창 식별자 할당 됩니다 공지 사항.
주 창 크기 및 위치를 자식 창을 주 창의 크기가 변경 될 때 받는 WM_SIZE 메시지에 응답에서 합니다. WM_SIZE에 대응, 주 창 GetWindowRect 함수를 사용 하 여 클라이언트 영역 크기를 검색 하 고 크기를 EnumChildWindows 함수에 전달 합니다. EnumChildWindows EnumChildProc 응용 프로그램 정의 콜백 함수를 차례로 각 자식 창에 대 한 핸들을 전달합니다. 이 기능은 크기 및 MoveWindow 함수; 호출 하 여 각 자식 창 위치 크기와 위치를 주 창 클라이언트 영역의 크기 및 자식 창 식별자에 기반 합니다. EnumChildProc 창을 볼 수 있도록 ShowWindow 함수를 호출 하는 이후에,.
#define ID_FIRSTCHILD 100
#define ID_SECONDCHILD 101
#define ID_THIRDCHILD 102
LONG APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rcClient;
int i;
switch(uMsg)
{
case WM_CREATE: // creating main window
// Create three invisible child windows.
for (i = 0; i < 3; i++)
{
CreateWindowEx(
0,
"ChildWClass",
(LPCTSTR) NULL,
WS_CHILD | WS_BORDER,
0,0,0,0,
hwnd,
(HMENU) (int) (ID_FIRSTCHILD + i),
hinst,
NULL);
}
return 0;
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);
return 0;
// Process other messages.
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
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;
}