P. Avery
P. Avery

Reputation: 809

MDI Child Window Size

I am trying to create a child window within an MDI MainWindow...The main window is 1024 x 768 in size...when I try to use CreateWindowEx() to create a child window the size seems to be offset somehow...in other words a 1024 x 768 child window is smaller than its parent...how can I account for this difference? When I use GetCLientRect() with the main window's handle...the size is still smaller...I don't care to make the child window the same size. I want the child window to encompass the exact size of an image that is 750x563. When I set that size within the parameters of CreateWindowEx(), the child window is too small...

Here is the code I use within the MainWndProc to create a child window:

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT Msg,
                             WPARAM wParam, LPARAM lParam)
{
    HDC          hdc;
    PAINTSTRUCT  ps;

    switch(Msg)
    {
        case WM_CREATE:
            {
                //OnCreate(hWnd, NULL);
                CLIENTCREATESTRUCT ccs;

                ccs.hWindowMenu  = GetSubMenu(GetMenu(hWnd), 2);
                ccs.idFirstChild = StartChildrenNo;

                hWndChildFrame = CreateWindowEx(WS_EX_CLIENTEDGE,
                    L"MDICLIENT",
                    NULL,
                    WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL
                    | WS_HSCROLL | WS_VISIBLE,
                    0,
                    0,
                    1024,
                    768,
                    hWnd,
                    (HMENU)IDM_FILE_NEW,
                    GetModuleHandle(NULL),
                    (LPVOID)&ccs);

                if(hWndChildFrame == NULL)
                    MessageBox(hWnd, L"Could not create MDI client.", L"Error", MB_OK | MB_ICONERROR);

                CreateNewMDIChild(hWndChildFrame);              
                                return 0;
            }

... }

Upvotes: 0

Views: 1305

Answers (1)

mity
mity

Reputation: 2349

  1. To determine size how the MDI child window can be large, use GetClientRect() of the MDI client window.

  2. To compute needed window size for the MDI child window use AdjustWindowRect() or AdjustWindowRectEx(). Those can convert between window and client size.

Upvotes: 1

Related Questions