SysTools Logo SysTools


C, WinAPI: MDIClient fullscreen height and scrollbars bugfixes


// PATCH: MDIClient fullscreen height and scrollbars bugfixes
// References and documentation links for this code:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644909.aspx
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms632602.aspx

// ...

// main window procedure
LRESULT CALLBACK MainWndProc(HWND wnd, UINT msg, WPARAM wparm, LPARAM lparm) {
CLIENTCREATESTRUCT ccs;
HWND wh;
RECT rc;

  // ...

  // get MDI client window handle
  wh = GetDlgItem(wnd, 0xCAC);

  // ...

  switch (msg) {

    // ...

    case WM_CREATE:
      ccs.hWindowMenu = GetSubMenu(GetMenu(wnd), WINDOWMENU);
      ccs.idFirstChild = IDM_WINDOWCHILD;
      // get parent window area
      GetClientRect(wnd, &rc);
      // create the MDI client window
      wh = CreateWindow(
        TEXT("MDIClient"), NULL,
        WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
        0, 0, rc.right, rc.bottom, // windows size
        wnd, (HMENU) 0xCAC,
        GetModuleHandle(NULL),
        &ccs
      );
      if (!wh) {
        MessageBox(wnd, TEXT("CreateWindow() for MDIClient failed!"), NULL, MB_ICONERROR);
        return(-1);
      }
      break;

    // ...

    case WM_SIZE:
      // get parent window area
      GetClientRect(wnd, &rc);
      // resize MDI client window
      MoveWindow(wh, 0, 0, rc.right, rc.bottom, TRUE);
      // rearrange minimized items for new MDI client window size
      PostMessage(wh, WM_MDIICONARRANGE, 0, 0);
      // PATCH: DO NOT return() here!
      // (so many bad examples on Internet which do return(0) here)
      // this message MUST BE passed to DefFrameProc()
      // or after minimize/restore main window MDIClient window
      // got broken horizontal and vertical scroll bars
      // (if any of the MDI children goes out of right or bottom
      // MDIClient window area)
      break;

    // ...

  }

  return(DefFrameProc(wnd, wh, msg, wparm, lparm));
}

// MDI children procedure
LRESULT CALLBACK MDIChildProc(HWND wnd, UINT msg, WPARAM wparm, LPARAM lparm) {

  // ...

  switch (msg) {

    // ...

    // PATCH: Windows MDI bottom padding bug at fullscreen
    case WM_GETMINMAXINFO:
      if (IsZoomed(wnd)) {
        ((PMINMAXINFO) lparm)->ptMaxTrackSize.y += GetSystemMetrics(SM_CYCAPTION);
      }
      break;

    // ...

  }

  return(DefMDIChildProc(wnd, msg, wparm, lparm));
}

2015.04.16


[ Код ]