|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
AbstractThe article presents three simple methods of routing Introduction to the problemThe standard framework route does not include inactive views, which causes toolbar buttons and menus to gray when their mother view is deactivated. Users are confused. I present three simple methods to bring their happiness back. :) All solutions base on overriding the In each case, the overridden function browses through a list of views and calls Classic document/view caseThe first quite obvious method is to use a list of views that is available in the BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { CDocument *pDoc = GetActiveDocument(); if(pDoc) { POSITION pos = pDoc->GetFirstViewPosition(); CView *pView = NULL; while(pView = pDoc->GetNextView(pos)) { if(pView != GetActiveView() && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; } } return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } Splitter window caseWhat if we didn’t like to use any BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { if(m_wndSplitter.GetSafeHwnd()) { int rc = m_wndSplitter.GetRowCount(), cc = m_wndSplitter.GetColumnCount(); for(int r = 0; r < rc; r++) for(int r = 0; r <ec; r++) { CWnd *pWnd = m_wndSplitter.GetPane(r, c); if(pWnd != m_wndSplitter.GetActivePane() && pWnd->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; } } return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } A possibly universal caseA young eager mind would then like to have a universal handler, independent of existence of member splitters or even a document. Seeking inspiration in MFC sources, namely BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { 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 CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); } As with the first method, the handler doesn’t have to be called for all views, as the calls may be freely filtered. It may be even done dynamically, e.g. depending on There is no possibility that these snippets would solve all your trouble with MFC command message routing, but it may get you closer or simply bring you a little clue. Any comments and suggestions are warmly welcome.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||