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

    Routing messages from CView to CDockablePane

    I have a MDI app, with CView based on CEditView, and in CMainFrame, I have a CDockablePane where I stretched a CRichEditCtrl. Everything goes well, except that messages from CMyDockablePane is routed to CMyEditView, so it is not what I want, if the focus is on CMyDockablePane.

    In detail, if I go to CMyDockablePane, and try to do a "Paste", the "Paste" operation is done it in CMyEditView.

    An interesting thing: If I do "Ctrl+Shift+V", then the "Paste" operation is done in CMyDockablePane.

    My Question is, how can I route MFC commands from CMyEditView to CMyDockablePane, if I got the focus inside my CMyDockablePane ?

    I have tried this:

    Code:
    BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    	if (m_wndClassView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))  // m_wndClassView is my CMyDockablePane
    		return TRUE;
    
    	return CMDIFrameWndEx::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }
    Didn't worked. I have attached here a sample project:
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2009
    Posts
    399

    Re: Routing messages from CView to CDockablePane

    P.S. I already read this article: https://www.codeproject.com/articles...-cdockablepane

    And I have applied that solution (simplified):
    Code:
    BOOL CMainFrame::OnCmdMsg(UINT id,int code , void *pExtra,AFX_CMDHANDLERINFO* pHandler)
    {
      //route cmd first to registered dockable pane
      POSITION pos = m_regCmdMsg.GetHeadPosition();
      while (pos)
      {
        CBasePane* pane = m_regCmdMsg.GetAt(pos);
        if(pane->IsVisible() &&
        pane->OnCmdMsg(id,code,pExtra,pHandler))
                                return TRUE;
        m_regCmdMsg.GetNext(pos);
      }
      return CFrameWndEx::OnCmdMsg(id,code,pExtra,pHandler);
    }
    but still not working.
    Last edited by mesajflaviu; July 2nd, 2021 at 12:11 AM.

  3. #3
    Join Date
    Jan 2009
    Posts
    399

    Re: Routing messages from CView to CDockablePane

    I have tried to route those messages from CMEdityView to CMyDOckablePane, like this:
    Code:
     BOOL CBBBView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
     {
      // TODO: Add your specialized code here and/or call the base class
        
      CMainFrame* pFrame = static_cast<CMainFrame*>(AfxGetMainWnd());
      if (pFrame->m_wndClassView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
      return TRUE;
        
      return CEditView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
     }
    Still not working. I routed the MFC messages correctly (I guess), but still not have the correct functionality.

  4. #4
    Join Date
    Jan 2009
    Posts
    399

    Re: Routing messages from CView to CDockablePane

    What I have noticed by now: I overriden OnCmdMsg in CMainFrame, CChildFrame and CMyView. Nothing worked.

    Then, I overriden CMyPanel:

    Code:
    BOOL CClassView::PreTranslateMessage(MSG* pMsg)
    {
    	// TODO: Add your specialized code here and/or call the base class
    
    	if (WM_KEYDOWN == pMsg->message && GetKeyState(VK_CONTROL) < 0)
    	{
    		switch (pMsg->wParam)
    		{
    		case 'Z':
    		case 'X':
    		case 'C':
    		case 'V':
    		case 'A':
    			TRACE("\n===============\n");
    			return TRUE;
    		}
    	}
    
    	return CDockablePane::PreTranslateMessage(pMsg);
    }
    In this case, I trap those events, Ctrl+C(X, V, A, etc.), but how can I send them to my CMyPanel to gain those functionality ?

    And one more (VERY) interesting thing: why I need to press 'Shift' key to have Copy/Paste functionality in CMyPanel ?

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

    Re: Routing messages from CView to CDockablePane

    Wenn I needed to communicate with Windows messages between the classes that do not belong (or at least one class does not belong) to the standard Microsoft classes involved to the "routing" and when one of these classes has no way to know how to obtain the handles of the other class' windows I just use CWnd::SendMessageToDescendants calling it from some of the parent frame (CMainFrame ot CChildFrame) classes.
    create the user defined register message IDs (RegisterWindowMessage) and handle each of these messages only in the classes that need it/them
    Victor Nijegorodov

  6. #6
    Join Date
    Jan 2009
    Posts
    399

    Re: Routing messages from CView to CDockablePane

    Thank you Victor. Seem to be a very good idea. I want to implement it, but I need only few more details: where can I catch (in CMainFrame or CChildFrame) the messages that interest me: Cut/Copy/Paste/Unde/Redo ? Are you thinking about PreTranslateMessage ?
    Last edited by mesajflaviu; July 6th, 2021 at 08:37 AM.

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