Effective Client area of an MDI application without an active CView

72 views Asked by At

I have an MDI application with numerous docking bars etc. I would like to know how to acquire the effective client area of the CView region without any such CView's existing.

Should such a view exist I can simply get its window size but at this stage it doesn't or may NOT.

Using the following from a DLL:

CRect  oCRectClient;
AfxGetApp()->GetMainWnd()->GetClientRect(&oCRectClient);

returns the whole CMDIFrameWndEx client area including those regions occupied by the docked panes.

2

There are 2 answers

0
Ed Dore On

The CMDIFrameWndEx class manages multiple child windows, including menu bar, toolbars, docked toolwindows, and the MDIClient window that provides functionality for hosting MDI Child windows.

https://learn.microsoft.com/en-us/cpp/mfc/managing-mdi-child-windows?view=msvc-170

In VS, right click on the CMDIFrameWndEx class your CMainFrame derives from, and select "Go To Definition" from the context menu. Note the protected m_wndClientArea member. As long as you are in the context of a CMainFrame method, you can readily retrieve the client area of the MDIClient by simply invoking something like:

RECT rect;
m_wndClientArea.GetClientRect(&rect);
0
Constantine Georgiou On

From inside the DLL code you can use the m_hWndMDIClient member of the CMDIFrameWnd class. It is easy to use because it's public. It is OK to use CMDIFrameWnd, even if your application's main window is actually CMDIFrameWndEx-derived, as CMDIFrameWndEx is CMDIFrameWnd-derived too. So the only assumption your DLL will be making is that the main application Window is CMDIFrameWnd-derived.

You have to use the Win32 GetClientRect() function (not the MFC one) because m_hWndMDIClient is of type HWND. Therefore your code could be:

CRect  oCRectClient;
GetClientRect(((CMDIFrameWnd*)AfxGetApp()->GetMainWnd())->m_hWndMDIClient, oCRectClient);