15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


UPDATE_COMMAND_UI for non-active view

Alexander Grigoriev -- alegr@aha.ru
Monday, November 18, 1996

Environment: MSVC 4.2b, Win 95

Little question:

My app has several views. When the cursor is placed over one of views,
status bar pane shows the coordinates. The problem is that
UPDATE_COMMAND_UI, where I set the status bar text, is called only for the
active view. I'd like to have UPDATE_COMMAND_UI called for all views.
pCmdUI->ContinueRouting() does not work.




Syed -- sxs296@psu.edu
Tuesday, November 26, 1996

[Mini-digest: 2 responses]

At 06:56 AM 11/18/96 +0300, you wrote:
>Environment: MSVC 4.2b, Win 95
>
>Little question:
>
>My app has several views. When the cursor is placed over one of views,
>status bar pane shows the coordinates. The problem is that
>UPDATE_COMMAND_UI, where I set the status bar text, is called only for the
>active view. I'd like to have UPDATE_COMMAND_UI called for all views.
>pCmdUI->ContinueRouting() does not work.
>
>
Well the problem is only the active view will receive the command. So in
some rare cases, you might want to override OnCmdMsg of your CMainFrm. Then,
call up an active document which has its own function that will route all
the commands to available views. That way, even the inactive view will be
'informed' and therefore, the corresponding menu items will not gray out.
The _rough_ code is as follows:-

BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo
)
{
        if (CFrameWnd::OnCmdMsg(.....))
                return TRUE;
        // Get your active document here..
        // it goes with something like this.. i'm not really sure the syntax
// though
        CMyDocument *pDoc = (CMyDocument*)GetActiveDocument();
        if (pDoc)
                return pDoc->RouteCommandToAll(GetActiveView(), uID, nCode,
pExtra, pHandlerInfo);
        return FALSE;
}

then in the appropriate Document class, you declare *obviously* a function
RouteCommandToAll.

BOOL CMyDocument::RouteCommandToAll(CView *pView, UINT nID, int nCode, void*
pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
        POSITION pos = GetFirstViewPosition();
        while (pos)
        {
                CView *pNextView = GetNextView(pos);
                if (pNextView != pView)
                {
                if (((CCmdTarget*)pNextView)->OnCmdMsg(nID, nCode, pExtra,
                        pHandlerInfo))
                        return TRUE;
                }
        }
return FALSE;
}

However, if you have more than once document in an application, the command
routine might be slight more complicated.


-----From: "Doug Brubacher" 

     Since the MFC Command Routing does not include inactive views it is 
     not surprising that pCmdUI->ContinueRouting() does not work.
     
     Why don't you use a Mouse Move event over your views to update your 
     status bar with the coordinates.  This will give you the same results.
     
     Regards
     
     Doug Brubacher
     DouglasB@msn.com




Paul Martinsen -- pmartinsen@hort.cri.nz
Wednesday, November 27, 1996

Maybe you could call UpdateAllViews with an appropriate hint 
when the active views get the command update message.
Paul.
> My app has several views. When the cursor is placed over one of views,
> status bar pane shows the coordinates. The problem is that
> UPDATE_COMMAND_UI, where I set the status bar text, is called only for the
> active view. I'd like to have UPDATE_COMMAND_UI called for all views.
> pCmdUI->ContinueRouting() does not work.
> 
> 




| Вернуться в корень Архива |