CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2009
    Posts
    399

    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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Handle WM_LBUTTONDBLCLK on CMainFrame

    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2009
    Posts
    399

    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 ...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Handle WM_LBUTTONDBLCLK on CMainFrame

    Victor Nijegorodov

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Handle WM_LBUTTONDBLCLK on CMainFrame

    Dear mesajflaviu, if that short explanation is for you too hard to understannd, please have a look at this blog.
    Victor Nijegorodov

  6. #6
    Join Date
    Jan 2009
    Posts
    399

    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 ...

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Handle WM_LBUTTONDBLCLK on CMainFrame

    Quote Originally Posted by mesajflaviu View Post
    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

  8. #8
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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:
    1. override CMDIFrameWnd::CreateClient;
    2. get "MdiClient" class info in a WNDCLASS structure;
    3. set WNDCLASS::lpszClassName with our own string and add CS_DBLCLKS flag to WNDCLASS::style;
    4. register the class;
    5. create MDI client window (can copy/paste the code from CMDIFrameWnd::CreateClient and replace the hard-coded "mdiclient" with our own class name;
    6. override PreTranslateMessage in main frame class.
    7. 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);
    }
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  9. #9
    Join Date
    Jan 2009
    Posts
    399

    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.

  10. #10
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    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).
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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
  •  





Click Here to Expand Forum to Full Width

Featured