How to Detect Mouse Clicks on Client Area of MDI Frame WindowsID: Q133716
|
You can detect when a user clicks the mouse while the pointer is over the client area of your main MDI frame window (the area of the client not covered by any open MDI child windows). To do so, you must first subclass the MDIClient so you can intercept the mouse messages being sent to it. This article shows by example how to do it using MFC. You can extend the method outlined here to handle any messages sent to the MDIClient.
To manage its MDI child windows, the CMDIFrameWnd class creates a window of
the class "mdiclient" to cover its entire client area (also referred to as
the Application Workspace). MFC stores a handle to this MDIClient window in
a public member variable, m_hWndMDIClient, of the CMDIFrameWnd class.
The MDIClient is a standard Windows window, not an MFC object. However,
subclassing it allows you to treat it just as you would any other CWnd,
taking advantage of standard MFC features like message maps. For example,
you could use this technique to provide a context menu when the user clicks
the right mouse button. Or, as the Windows 95 desktop does, you could use
it to provide an easy means of selecting a group of iconized MDI child
windows, enclosing them within a tracker rectangle as the user drags with
the left mouse button button held down.
Q129471 How to SubClass the MDIClient by Using MFC
WNDPROC* CMyMDIClient::GetSuperWndProcAddr()
{
static WNDPROC NEAR pfnSuper = NULL;
return &pfnSuper;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// Call the base class implementation to create the MDIClient
// window.
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// Subclass the MDIClient window.
if (!m_MyMDIClient.SubclassWindow(m_hWndMDIClient))
{
TRACE ("Failed to subclass MDI client window\n");
return (-1);
}
...
}
void CMyMDIClient::OnRButtonDown(UINT nFlags, CPoint point)
{
POINT ScreenPoint = point;
CMenu* pMenuTrackPopup;
// Get a pointer to the app's File menu popup.
// AfxGetMainWnd() returns a pointer to the main frame window,
// GetMenu() returns a pointer to the main menu of the application,
// and GetSubMenu(0) retrieves the submenu at position 0 (here the
// File menu).
pMenuTrackPopup = ((AfxGetMainWnd())->GetMenu())->GetSubMenu(0);
// Convert the mouse point to screen coordinates since that is what
// TrackPopupMenu() expects.
ClientToScreen(&ScreenPoint);
// Draw and track the "floating" popup
pMenuTrackPopup->TrackPopupMenu(TPM_RIGHTBUTTON,
ScreenPoint.x, ScreenPoint.y,
AfxGetMainWnd(), // Use the 'this' pointer if you want
// commands to be handled in your
// CMyMDIClient class instead
NULL);
// NOTE: Do not destroy this menu here!
// Call the base class
CWnd::OnRButtonDown(nFlags, point);
}
Additional query words: kbinf 1.50 1.51 1.52 1.00 2.00 2.10 2.50 2.51 2.52 2.10 2.20 3.00 3.10 4.00 4.10 4.20
Keywords : kbcode kbMFC KbUIDesign kbVC
Version : 1.50 1.51 1.52 | 1.00 2.00 2.10
Platform : NT WINDOWS
Issue type :
Last Reviewed: August 5, 1999