-
March 15th, 2017, 02:50 AM
#1
Handle WM_LBUTTONDBLCLK on CMainFrame
Is there a way to handle WM_LBUTTONDBLCLK on MDI client area ? I have tried something like this:
Code:
void CMainFrame::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// Do some things ...
CMDIFrameWndEx::OnLButtonDblClk(nFlags, point);
}
But the execution doesn't pass by here ... And more important thing: CMainFrame is derived from CMDIFrameWndEx, not from CMDIFrameWnd ...
I have seek something similar on internet, but I have found the way to draw something in MDI client area, not handle this event ...
Thank you.
Last edited by mesajflaviu; April 24th, 2017 at 04:46 AM.
-
March 15th, 2017, 05:03 AM
#2
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Victor Nijegorodov
-
March 15th, 2017, 05:19 AM
#3
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
I have tried:
Code:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
return -1;
if (! m_wndMDIClient.SubclassWindow(m_hWndMDIClient))
{
MessageBox(_T("Failed to subclass MDI Client"));
return -1;
}
where m_wndMDIClient is:
Code:
class CMDIClientWnd : public CWnd
{
// Construction
public:
CMDIClientWnd();
...
protected:
//{{AFX_MSG(CMDIClientWnd)
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
the problem become here:
Code:
if (! m_wndMDIClient.SubclassWindow(m_hWndMDIClient)) // <-- crash
{
MessageBox(_T("Failed to subclass MDI Client"));
return -1;
}
Debug Assertion Failed: wincore.cpp line 330: "ASSERT(FromHandlePermanent(hWndNew) == NULL);"
Strange ...
-
March 15th, 2017, 05:33 AM
#4
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Victor Nijegorodov
-
March 18th, 2017, 09:03 AM
#5
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Originally Posted by VictorN
Dear mesajflaviu, if that short explanation is for you too hard to understannd, please have a look at this blog.
Victor Nijegorodov
-
March 21st, 2017, 05:47 AM
#6
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Kindly thank you for the answers, by now, all the solutions reveal how to draw inside of MDI client area (in a way or other), and my request say to catch double-click event in MDI client area ... I have to dig in ...
-
March 21st, 2017, 06:09 AM
#7
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Originally Posted by mesajflaviu
Kindly thank you for the answers, by now, all the solutions reveal how to draw inside of MDI client area (in a way or other), and my request say to catch double-click event in MDI client area ... I have to dig in ...
You are welcome! And good luck in deeper dig in!
Victor Nijegorodov
-
March 22nd, 2017, 11:01 AM
#8
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Subclassing our own CMDIClientAreaWnd-derived class, can lead in weird behaviors because CMDIFrameWndEx internaly use its own m_wndClientArea.
Anyway, if you have a look with Spy++ tool (shiped with Visual C++), you can observe that client MDI window (of pre-defined class "MdiClient") do not receive WM_LBUTTONDBLCLK message. That's simply because "MdiClient" class has not CS_DBLCLKS style.
Here is a workaround which solves your problem:
- override CMDIFrameWnd::CreateClient;
- get "MdiClient" class info in a WNDCLASS structure;
- set WNDCLASS::lpszClassName with our own string and add CS_DBLCLKS flag to WNDCLASS::style;
- register the class;
- create MDI client window (can copy/paste the code from CMDIFrameWnd::CreateClient and replace the hard-coded "mdiclient" with our own class name;
- override PreTranslateMessage in main frame class.
- enjoy of WM_LBUTTONDBLCLK message forwarded by the MDI client window.
Here is the sample code:
Code:
#define OUR_OWN_CLASS_NAME _T("BABA-SAFTA-MDI-CLIENT")
// ...
BOOL CMainFrame::CreateClient(LPCREATESTRUCT lpCreateStruct, CMenu* pWindowMenu)
{
// Do not call CMDIFrameWndEx::CreateClient
WNDCLASS wndClass = { 0 };
if (!::GetClassInfo(AfxGetInstanceHandle(), _T("MdiClient"), &wndClass))
return FALSE;
wndClass.lpszClassName = OUR_OWN_CLASS_NAME;
wndClass.style |= CS_DBLCLKS;
AfxRegisterClass(&wndClass);
// Next is copy-pasted from MFC implementation except that use our class name
// ...
// ...
// Create MDICLIENT control with special IDC
if ((m_hWndMDIClient = CreateWindowEx(dwExStyle, OUR_OWN_CLASS_NAME, NULL,
dwStyle, 0, 0, 0, 0, m_hWnd, (HMENU)AFX_IDW_PANE_FIRST,
AfxGetInstanceHandle(), (LPVOID)&ccs)) == NULL)
{
// ...
// ...
Code:
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if ((pMsg->message == WM_LBUTTONDBLCLK) && (pMsg->hwnd == m_hWndMDIClient))
{
AfxMessageBox(_T("Bau-bau!"));
}
return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}
-
March 24th, 2017, 03:05 AM
#9
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
Is working like a charm !! Kindly thank you Ovidiu !
Last edited by mesajflaviu; March 26th, 2017 at 01:59 PM.
-
March 30th, 2017, 11:07 AM
#10
Re: Handle WM_LBUTTONDBLCLK on CMainFrame
You are welcome.
I just have published a little article about handling double-click in MDI Client which shows the solution for standard MDI applications (in which CMainFrame is derived from CMDIFrameWnd) and for the ohers (Visual Studio-style and Office-style MDI applications, in which CMainFrame is derived from CMDIFrameWndEx).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|