1

I have a CMDIChildWnd containing a CReportView (child) within a CFormView (parent). The CMDIChildWnd also has a toolbar which sends ON_UPDATE_COMMAND_UI to it's child view. That works so far. Now, whenever the CReportView is activated (e.g. clicking on it), the ON_UPDATE_COMMAND_UI messages arrive at the CReportView, not the parent CFormView.

What I want to do now is catching the ON_UPDATE_COMMAND_UI messages in the child view and relay them to the parent view somehow. I tried overriding the CWnd::PreTranslateMessage() method and calling the parent view's SendMessage() method, but the ON_UPDATE_COMMAND_UI didn't arrive there.

I also tried the following

BEGIN_MESSAGE_MAP(CUntisSimpleGrid, CReportView)
    ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdate)
END_MESSAGE_MAP()

LRESULT CUntisSimpleGrid::OnIdleUpdate(WPARAM wParam, LPARAM lParam)
{
    CWnd *pParentView = GetParent();
    UpdateDialogControls(pParentView, FALSE);
    return 0L;
}

But that didn't work either. Does anyone have an idea?

IInspectable
  • 46,945
  • 8
  • 85
  • 181
koloman
  • 711
  • 7
  • 19
  • 1
    Hi, I don't know where CReportView (the Report control from CodeProject?) comes from, but to solve this issue I would take a look at this article here http://www.microsoft.com/msj/0795/dilascia/dilascia.aspx and on overriding OnCmdMsg. Hope this helps. – Clemens Jan 10 '13 at 19:26
  • Yes, sir! That helped! I've solved the issue by overriding `OnCmdMsg` in the `CMDIChildWnd`. The article is wonderful. A must read for every developer who is serious about MFC. – koloman Jan 11 '13 at 07:37

1 Answers1

1

I've solved the issue by overriding OnCmdMsg in the CMDIChildWnd. Now, after trying to dispatch a message the usual way, the CMDIChildWnd also tries to dispatch the message to its inactive views and stops after one of them handles the message.

BOOL CShowLessonsChildFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    CPushRoutingFrame push(this);

    // pump through current view FIRST
    CView* pView = GetActiveView();
    if (pView != NULL && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;

    // then pump through frame
    if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;

    // last but not least, pump through app
    CWinApp* pApp = AfxGetApp();
    if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;

    // Now try to dispatch the message to inactive windows and see if
    // one of them handles the message
    for(UINT id = AFX_IDW_PANE_FIRST; id <= AFX_IDW_PANE_LAST; id++)
    {
        CWnd *pWnd = GetDescendantWindow(id, TRUE);
        if(pWnd && pWnd != GetActiveView()
            && pWnd->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;
    }

    return FALSE;
}
koloman
  • 711
  • 7
  • 19