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:
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 ?
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
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.