Question

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?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top