Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

c++ - How can I handle the resize of children windows when the parent windows is resized?

So I have been trying to accomplish this for a bit now. I am having trouble handling the resize of the children windows when the parent window is resized. When I do not handle the resize, the parent window is resized and the child windows stay in the same place.

I have know that this has to be in the message of WM_SIZE but I do not know how to handle the rest from there. I have tried the MoveWindow() and UpdateWindow() function but it didn't seem to work for me.

I have been trying to get this window child to resize correctly: hName = CreateWindowW(L"Edit", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 200, 50, 98, 38, hWnd, NULL, NULL, NULL);. So far nothing has worked. Help is appreciated! Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I use a global RECT to storage the left, top, width and height of Edit control(RECT editSize = { 100, 50 , 100, 100 }) . In WM_SIZE message, call EnumChildWindows, resize my child windows in 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;
}

enter image description here

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...