唉,又是一声叹息。为什么就不去查查MSDN呢?MSDN上的例子最能说明问题了。 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; 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;
// 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;
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;
}
void find_button()
{
// hwnd is the handle of the parent
// lpsz is the caption of the button
EnumChildWindows(hwnd, EnumChildProc, (LPARAM)lpsz );
}// callback
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
// GetWindowText 獲取子窗口Caption,與lParam比較,如果匹配,則是目標窗口,返回FALSE中止查找 return TRUE; // 繼續枚舉子窗口
}