cdonts
cdonts

Reputation: 9599

How to set size and position of a MDI Client?

It seems like both size (x, y) and position (nWidth, nHeight) arguments are ignored when using CreateWindow. For example:

CreateWindow(L"MDICLIENT", L"", WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
             150, 10, 400, 300, hWnd, NULL, hInst, (LPVOID)&ccs);

It's always aligned to the top-left corner and takes the parent's size, as shown below.

enter image description here

(We could see the difference since the window background is COLOR_WINDOW).

Upvotes: 1

Views: 823

Answers (1)

Barmak Shemirani
Barmak Shemirani

Reputation: 31599

The coordinates for MDICLIENT have no effect on start up. Instead you have to handle client-size in WM_SIZE as follows:

LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND hwndClient;
    switch (message)
    {

    case WM_CREATE:
    {
        hwndClient = CreateWindow(L"MDICLIENT", L"", WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
            0, 0, 0, 0, hWnd, NULL, hInst, (LPVOID)&ccs);
        ...
        return 0;
    }

    case WM_SIZE:
    {
        RECT rc;
        GetClientRect(hwnd, &rc);

        SetWindowPos(hwndToolbar, 0, 0, 0, rc.right, 30, SWP_SHOWWINDOW);

        int x = 50; //right-edge of another toolbar...
        int y = 30;
        int w = rc.right - x;
        int h = rc.bottom - y;
        MoveWindow(hwndClient, x, y, w, h, 0);
        return 0;
    }
    ...
}

By the way, you won't really see any difference on the screen unless you add MDI child. The MDI child will limit its movements to the new area, it won't go over the toolbar.

Upvotes: 3

Related Questions