1

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).

4

1 回答 1

3

的坐标MDICLIENT对启动没有影响。相反,您必须WM_SIZE按如下方式处理客户端大小:

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;
    }
    ...
}

顺便说一句,除非您添加 MDI 子项,否则您不会真正在屏幕上看到任何差异。MDI 子项会将其移动限制在新区域,它不会越过工具栏。

于 2015-11-01T02:56:20.383 回答