当 parent windows 调整大小时,如何处理 children windows 的调整大小?
How can I handle the resize of children windows when the parent windows is resized?
所以我一直在尝试完成这个。当 parent window 调整大小时,我无法处理 children windows 的调整大小。当我不处理调整大小时,parent window 被调整大小并且 child windows 留在同一个地方。
我知道这必须在 WM_SIZE 的消息中,但我不知道如何处理那里的其余部分。我尝试了 MoveWindow() 和 UpdateWindow() 函数,但它似乎对我不起作用。
我一直在努力让这个 window child 正确调整大小:
hName = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 200, 50, 98, 38, hWnd, NULL, NULL, NULL);
。到目前为止,没有任何效果。感谢帮助!谢谢!
我使用一个全局的RECT
来存储Edit control(RECT editSize = { 100, 50 , 100, 100 }
)的左边、顶部、宽度和高度。
在 WM_SIZE
消息中,调用 EnumChildWindows
,在 EnumChildProc
中调整我的 child windows 的大小
case WM_SIZE:
GetClientRect(hWnd, &rcClient);
EnumChildWindows(hWnd, EnumChildProc, (LPARAM)&rcClient);
return 0;
EnumChildProc
:
#define ID_Edit1 200
...
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
int idChild;
idChild = GetWindowLong(hwndChild, GWL_ID);
LPRECT rcParent;
rcParent = (LPRECT)lParam;
if (idChild == ID_Edit1) {
//Calculate the change ratio
double cxRate = rcParent->right * 1.0 / 884; //884 is width of client area
double cyRate = rcParent->bottom * 1.0 / 641; //641 is height of client area
LONG newRight = editSize.left * cxRate;
LONG newTop = editSize.top * cyRate;
LONG newWidth = editSize.right * cxRate;
LONG newHeight = editSize.bottom * cyRate;
MoveWindow(hwndChild, newRight, newTop, newWidth, newHeight, TRUE);
// Make sure the child window is visible.
ShowWindow(hwndChild, SW_SHOW);
}
return TRUE;
}
所以我一直在尝试完成这个。当 parent window 调整大小时,我无法处理 children windows 的调整大小。当我不处理调整大小时,parent window 被调整大小并且 child windows 留在同一个地方。
我知道这必须在 WM_SIZE 的消息中,但我不知道如何处理那里的其余部分。我尝试了 MoveWindow() 和 UpdateWindow() 函数,但它似乎对我不起作用。
我一直在努力让这个 window child 正确调整大小:
hName = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 200, 50, 98, 38, hWnd, NULL, NULL, NULL);
。到目前为止,没有任何效果。感谢帮助!谢谢!
我使用一个全局的RECT
来存储Edit control(RECT editSize = { 100, 50 , 100, 100 }
)的左边、顶部、宽度和高度。
在 WM_SIZE
消息中,调用 EnumChildWindows
,在 EnumChildProc
case WM_SIZE:
GetClientRect(hWnd, &rcClient);
EnumChildWindows(hWnd, EnumChildProc, (LPARAM)&rcClient);
return 0;
EnumChildProc
:
#define ID_Edit1 200
...
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
int idChild;
idChild = GetWindowLong(hwndChild, GWL_ID);
LPRECT rcParent;
rcParent = (LPRECT)lParam;
if (idChild == ID_Edit1) {
//Calculate the change ratio
double cxRate = rcParent->right * 1.0 / 884; //884 is width of client area
double cyRate = rcParent->bottom * 1.0 / 641; //641 is height of client area
LONG newRight = editSize.left * cxRate;
LONG newTop = editSize.top * cyRate;
LONG newWidth = editSize.right * cxRate;
LONG newHeight = editSize.bottom * cyRate;
MoveWindow(hwndChild, newRight, newTop, newWidth, newHeight, TRUE);
// Make sure the child window is visible.
ShowWindow(hwndChild, SW_SHOW);
}
return TRUE;
}