Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
David Skok
|
May 31, 2006 - 9:04 AM
|
Greetings!
In my application I use the OnMDIActivate message to synchronize other displays with the active MDI view.
The following code is abbreviated for simplicity and worked fine in v2.53 but now does not work correctly in v2.54. I also did a quick check by replacing the Splitter frame in the DrawCli sample with an overidden CMDIChild and it was broke there also.
class DrawFrame : public CMDIChild { ...
void DrawFrame::OnMDIActivate( BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd ) { CDocument *pDoc;
CMDIChildWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
if( !bActivate || !pActivateWnd ) return;
if( pActivateWnd->IsKindOf( RUNTIME_CLASS(CMDIChildWnd) ) ) pDoc = ((CMDIChildWnd*) pActivateWnd)->GetActiveDocument();
// ......use pDoc to tell non-views what doc is focused }
GetActiveDocument() returns the active document for the first MDIChild created and for every subsequent child created if the children are not maximized. If the children are maximized GetActiveDocument() returns the correct pDoc for the first new document but NULL for every subsequent "new". In either case (maximized or not) switching between views always returns the active document. It just so happens that my app always operates on maximized views.
Thanks
|
|
Technical Support
|
Jun 1, 2006 - 3:07 AM
|
Thank you for reporting the bug. Please update the source code of the CExtMenuControlBar::OnHookWndMsg() method in the ExtPopupMenuWnd.cpp file: bool CExtMenuControlBar::OnHookWndMsg(
LRESULT & lResult,
HWND hWndHooked,
UINT nMessage,
WPARAM & wParam,
LPARAM & lParam
)
{
__PROF_UIS_MANAGE_STATE;
if( GetSafeHwnd() == NULL
|| (! ::IsWindow(GetSafeHwnd()) )
|| CWnd::FromHandlePermanent(GetSafeHwnd()) == NULL
|| _DraggingGetBar() != NULL
)
return
CExtHookSink::OnHookWndMsg(
lResult,
hWndHooked,
nMessage,
wParam,
lParam
);
HWND hWndMainFrame = NULL;
CWnd * pWndForPlacement = NULL;
if( ! m_bPresubclassDialogMode )
{
hWndMainFrame = _GetHwndMainFrame();
if( hWndMainFrame != NULL )
pWndForPlacement = stat_GetWndForPlacement( CWnd::FromHandle(hWndMainFrame) );
}
if( ( (!m_bPresubclassDialogMode)
&& ( ( hWndMainFrame != NULL
&& hWndHooked == hWndMainFrame
)
|| ( pWndForPlacement != NULL
&& hWndHooked == pWndForPlacement->m_hWnd
)
)
)
|| ( m_bPresubclassDialogMode
&& hWndHooked == _GetHwndPlacement()
)
)
{
if( nMessage == WM_PARENTNOTIFY
&&
CExtPopupMenuWnd::IsMenuTracking()
)
{
lResult = 0;
return true;
}
if( nMessage == WM_SIZE
|| nMessage == WM_ACTIVATEAPP
|| ( nMessage == WM_COMMAND
&& ( ((HIWORD(wParam))==0)
|| ((HIWORD(wParam))==1)
)
)
|| nMessage == WM_SYSCOMMAND
)
{
HWND hWndCapture = CExtMouseCaptureSink::GetCapture();
if( hWndCapture == GetSafeHwnd() )
CExtMouseCaptureSink::ReleaseCapture();
else if( hWndCapture != NULL )
{
CWnd * pWnd = FromHandlePermanent(hWndCapture);
if( pWnd != NULL
&& pWnd->GetSafeHwnd() != NULL
&& ::IsWindow( pWnd->GetSafeHwnd() )
&& pWnd->IsKindOf(RUNTIME_CLASS(CExtControlBar))
)
CExtMouseCaptureSink::ReleaseCapture();
}
_CancelFlatTracking();
if( CExtMenuControlBar::g_bMenuTracking )
CExtMenuControlBar::_CloseTrackingMenus();
return
CExtHookSink::OnHookWndMsg(
lResult,
hWndHooked,
nMessage,
wParam,
lParam
);
}
if( !m_bPresubclassDialogMode )
{
if( (nMessage == WM_NCLBUTTONUP && wParam == HTSYSMENU)
|| (nMessage == WM_NCRBUTTONUP && (wParam == HTCAPTION || wParam == HTSYSMENU))
)
{
CExtToolControlBar::g_bMenuTrackingExpanded = false;
CPoint * pPoint = NULL, ptCursor;
if( nMessage == WM_NCRBUTTONUP )
{
if( ! ::GetCursorPos(&ptCursor) )
{
lResult = 0;
return true;
}
pPoint = &ptCursor;
}
if( !_IsDockSiteCustomizeMode() )
{
if( ! TrackMainFrameSystemMenu(
pPoint,
FALSE
)
)
return false;
}
lResult = 0;
return true;
}
if( (nMessage == WM_NCLBUTTONDOWN || nMessage == WM_NCRBUTTONDOWN)
&& wParam == HTSYSMENU
)
{
lResult = 0;
if( (! m_bAllowProfMainFrameSysmenu )
&& hWndHooked == _GetHwndMainFrame()
)
return false;
if( (! m_bAllowProfChildFrameSysmenu )
&& _IsMdiApp()
&& hWndHooked == _GetHwndChildFrame()
)
return false;
return true;
}
if( nMessage == WM_NCRBUTTONDOWN && wParam == HTCAPTION )
{
if( !_IsDockSiteCustomizeMode() )
{
CExtToolControlBar::g_bMenuTrackingExpanded = false;
CPoint ptCursor;
if( ::GetCursorPos(&ptCursor) )
if( ! TrackMainFrameSystemMenu(
&ptCursor,
FALSE
)
)
return false;
}
lResult = 0;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgNotifyMenuClosed )
{
m_bSysMenuTracking = false;
return false;
}
}
bool bPrintPreviewMode = false;
if( (!m_bPresubclassDialogMode)
&& m_pDockSite->GetSafeHwnd() != NULL
&& FindPrintPreviewMode(m_pDockSite)
)
bPrintPreviewMode = true;
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupNext
|| nMessage == CExtPopupMenuWnd::g_nMsgPopupPrev
)
{
BOOL bDummyMax = FALSE;
HWND hWndMdiChild = _GetActiveMdiChildWnd(bDummyMax);
int iTrackingIndex =
GetMenuTrackingButton();
if( (!bPrintPreviewMode) && iTrackingIndex < 0 )
{
if( m_bSysMenuTracking )
{
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupNext
&& _IsMdiApp()
&& hWndMdiChild != NULL
&& IsDisplayMdiDocumentButtons()
)
{
ASSERT( !m_bPresubclassDialogMode );
if( ! TrackChildFrameSystemMenu(
NULL,
TRUE
)
)
{
if( m_bAllowProfChildFrameSysmenu )
return false;
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( iNewTrackIndex == iTrackingIndex )
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
}
}
else
{
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( iNewTrackIndex == iTrackingIndex )
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
}
}
lResult = 0;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupNext
&& ( !m_bPresubclassDialogMode )
&& iTrackingIndex == GetVisibleButton(-1,FALSE)
)
{
if( ! _IsDockSiteCustomizeMode() )
{
if( (! TrackMainFrameSystemMenu(
NULL,
TRUE
) )
)
{
if( m_bAllowProfMainFrameSysmenu )
return false;
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( bPrintPreviewMode
|| iNewTrackIndex == iTrackingIndex
)
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
lResult = 0;
return true;
}
}
lResult = 0;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupPrev
&& ( !m_bPresubclassDialogMode )
&& iTrackingIndex == 0
&& IsDisplayMdiDocumentButtons()
)
{
if( ! _IsDockSiteCustomizeMode() )
{
if( (! (_IsMdiApp() && hWndMdiChild != NULL ) )
|| bPrintPreviewMode
|| (! TrackChildFrameSystemMenu(
NULL,
TRUE
)
)
)
{
if( ! TrackMainFrameSystemMenu(
NULL,
TRUE
)
)
{
if( m_bAllowProfMainFrameSysmenu )
return false;
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( bPrintPreviewMode
|| iNewTrackIndex == iTrackingIndex
)
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
lResult = 0;
return true;
}
}
}
lResult = 0;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupNext
&& (!m_bPresubclassDialogMode)
&& _IsMdiApp()
&& m_bSysMenuTracking
&& iTrackingIndex < 0
&& hWndMdiChild != NULL
&& IsDisplayMdiDocumentButtons()
&& (!bPrintPreviewMode)
)
{
if( !_IsDockSiteCustomizeMode() )
if( ! TrackChildFrameSystemMenu(
NULL,
TRUE
)
)
return false;
lResult = 0;
return true;
}
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( (! IsDisplayMdiDocumentButtons() )
&& nMessage == CExtPopupMenuWnd::g_nMsgPopupPrev
&& iTrackingIndex == 0
&& iNewTrackIndex > 0
)
{
if( !_IsDockSiteCustomizeMode() )
if( ! TrackMainFrameSystemMenu(
NULL,
TRUE
)
)
return false;
lResult = 0;
return true;
}
if( bPrintPreviewMode
|| iNewTrackIndex == iTrackingIndex
)
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
lResult = 0;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgNotifyMenuExpanded )
{
CExtToolControlBar::g_bMenuTrackingExpanded = true;
lResult = 0;
return true;
}
if( ! m_bPresubclassDialogMode )
{
if( nMessage == WM_STYLECHANGING
|| nMessage == WM_STYLECHANGED
)
return false;
_KillFrameMenu();
}
}
else if( hWndHooked == _GetHwndChildFrame() )
{
if( nMessage == WM_PARENTNOTIFY
&& CExtPopupMenuWnd::IsMenuTracking()
)
{
lResult = 0;
return true;
}
if( nMessage == WM_SIZE
|| nMessage == WM_WINDOWPOSCHANGED
|| nMessage == WM_ACTIVATEAPP
|| ( nMessage == WM_COMMAND && (((HIWORD(wParam))==0)||((HIWORD(wParam))==1)) )
|| nMessage == WM_SYSCOMMAND
)
{
bool bSizePos = false;
if( nMessage == WM_SIZE )
bSizePos = true;
else if( nMessage == WM_WINDOWPOSCHANGED )
{
LPWINDOWPOS lpWP = (LPWINDOWPOS)lParam;
ASSERT( lpWP != NULL );
if( (lpWP->flags & SWP_FRAMECHANGED) == 0 )
bSizePos = true;
}
HWND hWndCapture = CExtMouseCaptureSink::GetCapture();
if( hWndCapture == GetSafeHwnd() )
CExtMouseCaptureSink::ReleaseCapture();
else if( hWndCapture != NULL )
{
CWnd * pWnd = FromHandlePermanent(hWndCapture);
if( pWnd != NULL
&& pWnd->GetSafeHwnd() != NULL
&& ::IsWindow( pWnd->GetSafeHwnd() )
&& pWnd->IsKindOf(RUNTIME_CLASS(CExtControlBar))
&& (! (((CExtControlBar*)pWnd)->_RowResizingGet() ) )
&& (! (((CExtControlBar*)pWnd)->_RowRecalcingGet() ) )
)
CExtMouseCaptureSink::ReleaseCapture();
}
_CancelFlatTracking();
if( CExtMenuControlBar::g_bMenuTracking )
CExtMenuControlBar::_CloseTrackingMenus();
if( CExtPopupMenuWnd::IsMenuTracking() )
CExtPopupMenuWnd::CancelMenuTracking();
if( !bSizePos )
{
_KillFrameMenu();
if( ( nMessage == WM_SIZE
|| nMessage == WM_WINDOWPOSCHANGED
)
&& (! _IsDockSiteCustomizeMode() )
)
{
WINDOWPLACEMENT _wp;
::memset( &_wp, 0, sizeof(WINDOWPLACEMENT) );
_wp.length = sizeof(WINDOWPLACEMENT);
::GetWindowPlacement( _GetHwndChildFrame(), &_wp );
if( _wp.showCmd != SW_SHOWMAXIMIZED
|| ( _GetButtonsCountImpl() > 0
&& (! _GetButtonPtr(0)->IsKindOf(RUNTIME_CLASS(CExtBarMdiDocButton)) )
&& ( IsDisplayMdiDocumentButtons() )
)
)
_DelayUpdateMenuBar();
}
}
return
CExtHookSink::OnHookWndMsg(
lResult,
hWndHooked,
nMessage,
wParam,
lParam
);
}
bool bPrintPreviewMode = false;
if( (!m_bPresubclassDialogMode)
&& m_pDockSite->GetSafeHwnd() != NULL
&& FindPrintPreviewMode(m_pDockSite)
)
bPrintPreviewMode = true;
if( bPrintPreviewMode )
{
lResult = 0;
return true;
}
bool bMinFrameNcLbDown = false;
bool bMinFrameNcLbUp = false;
if( nMessage == WM_NCLBUTTONDOWN
|| nMessage == WM_NCLBUTTONUP
)
{
WINDOWPLACEMENT _wp;
::memset( &_wp, 0, sizeof(WINDOWPLACEMENT) );
_wp.length = sizeof(WINDOWPLACEMENT);
::GetWindowPlacement( hWndHooked, &_wp );
if( _wp.showCmd == SW_SHOWMINIMIZED )
{
if( nMessage == WM_NCLBUTTONDOWN )
bMinFrameNcLbDown = true;
else if( nMessage == WM_NCLBUTTONUP )
bMinFrameNcLbUp = true;
}
}
if( bMinFrameNcLbUp && wParam == HTCAPTION )
return true;
if( ( bMinFrameNcLbDown && wParam == HTCAPTION )
|| (nMessage == WM_NCLBUTTONUP && wParam == HTSYSMENU)
|| (nMessage == WM_NCRBUTTONUP && (wParam == HTCAPTION || wParam == HTSYSMENU))
)
{
CExtToolControlBar::g_bMenuTrackingExpanded = false;
CPoint * pPoint = NULL, ptCursor;
if( nMessage == WM_NCRBUTTONUP )
{
if( ! ::GetCursorPos(&ptCursor) )
{
lResult = 0;
return true;
}
pPoint = &ptCursor;
}
if( !_IsDockSiteCustomizeMode() )
if( ! TrackChildFrameSystemMenu(
pPoint,
FALSE
)
)
return false;
lResult = 0;
return true;
}
if( (nMessage == WM_NCLBUTTONDOWN || nMessage == WM_NCRBUTTONDOWN)
&& wParam == HTSYSMENU
)
{
if( ! m_bAllowProfChildFrameSysmenu )
return false;
lResult = 0;
return true;
}
if( nMessage == WM_NCRBUTTONDOWN && wParam == HTCAPTION )
{
if( !_IsDockSiteCustomizeMode() )
{
CExtToolControlBar::g_bMenuTrackingExpanded = false;
CPoint ptCursor;
if( ::GetCursorPos(&ptCursor) )
if( ! TrackChildFrameSystemMenu(
&ptCursor,
FALSE
)
)
return false;
}
lResult = 0;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgNotifyMenuClosed )
{
m_bSysMenuTracking = false;
return true;
}
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupNext
|| nMessage == CExtPopupMenuWnd::g_nMsgPopupPrev
)
{
int iTrackingIndex =
GetMenuTrackingButton();
if( nMessage == CExtPopupMenuWnd::g_nMsgPopupPrev )
{
if( ! _IsDockSiteCustomizeMode() )
{
if( ! TrackMainFrameSystemMenu(
NULL,
TRUE
)
)
{
if( m_bAllowProfMainFrameSysmenu )
return false;
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( iNewTrackIndex == iTrackingIndex )
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
}
}
lResult = 0;
return true;
}
if( iTrackingIndex < 0 )
{
if( m_bSysMenuTracking )
{
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( iNewTrackIndex == iTrackingIndex )
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
}
lResult = 0;
return true;
}
int iNewTrackIndex =
GetVisibleButton(
iTrackingIndex,
(nMessage == CExtPopupMenuWnd::g_nMsgPopupNext) ?
TRUE : FALSE
);
if( iNewTrackIndex == iTrackingIndex )
{
lResult = 0;
return true;
}
TrackButtonMenu(iNewTrackIndex);
lResult = 0;
return true;
}
}
else if( hWndHooked == _GetHwndMdiArea() )
{
if( nMessage == WM_PARENTNOTIFY
&&
CExtPopupMenuWnd::IsMenuTracking()
)
{
lResult = 0;
return true;
}
if( nMessage == WM_MDISETMENU )
{
CFrameWnd * pFrame = _GetDockingFrameImpl();
ASSERT_VALID( pFrame );
HWND hWndFrame = pFrame->GetSafeHwnd();
ASSERT( hWndFrame != NULL );
ASSERT( ::IsWindow(hWndFrame) );
bool bOle = IsOleIpObjActive();
HMENU hOldMdiMenu = m_menuDoc.Detach();
HMENU hNewMdiMenu = (HMENU)wParam;
m_menuDoc.Attach( hNewMdiMenu );
if( bOle )
::SetMenu( hWndFrame, hNewMdiMenu );
else
{
HMENU hFrameRealMenu = ::GetMenu( hWndFrame );
if( hFrameRealMenu != NULL )
::SetMenu( hWndFrame, NULL );
_DelayUpdateMenuBar();
}
CExtHookSink::OnHookWndMsgNextProcCurrent( 0L, 0L );
lResult = (LRESULT)hOldMdiMenu;
_SyncActiveMdiChild();
m_bDelayedSyncActiveMdiChild = false;
return true;
}
if( nMessage == WM_MDIREFRESHMENU )
{
CExtHookSink::OnHookWndMsgNextProcCurrent( 0L, 0L );
_SyncActiveMdiChild();
m_bDelayedSyncActiveMdiChild = false;
lResult = 0;
return true;
}
if( nMessage == WM_CONTEXTMENU )
{
#if (!defined __EXT_MFC_NO_CUSTOMIZE)
CExtCustomizeSite * pSite =
CExtCustomizeSite::GetCustomizeSite( m_hWnd );
if( pSite != NULL
&& pSite->IsCustomizeMode()
)
{
lResult = 0;
return true;
}
#endif
if( !CExtControlBar::FindHelpMode(this) )
{
CFrameWnd * pFrame = _GetDockingFrameImpl();
ASSERT_VALID( pFrame );
CPoint ptCursor;
if( ! ::GetCursorPos(&ptCursor) )
{
lResult = 0;
return true;
}
HWND hWndTrack = GetOwner()->GetSafeHwnd();
ASSERT( hWndTrack != NULL && ::IsWindow(hWndTrack) );
CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
VERIFY( pPopup->CreatePopupMenu(hWndTrack) );
if( ! CExtDockBar::_ConstructDockSiteControlBarPopupMenu(
pFrame,
pPopup,
CExtControlBar::POPUP_MENU_EVENT_DATA::__PMED_MDICLIAREA_CTX,
this,
WM_CONTEXTMENU,
NULL
)
)
delete pPopup;
else
{
if( pPopup->ItemGetCount() == 0 )
delete pPopup;
else
{
::SetFocus( hWndTrack );
if( ! pPopup->TrackPopupMenu(
TPMX_OWNERDRAW_FIXED,
ptCursor.x,
ptCursor.y,
NULL,
this,
NULL,
NULL,
true
)
)
delete pPopup;
}
}
}
lResult = 0;
return true;
}
if( nMessage == WM_MDIACTIVATE
|| nMessage == WM_MDIDESTROY
|| nMessage == WM_MDINEXT
)
{
if( nMessage == WM_MDINEXT
&& IsOleIpObjActive()
)
{
lResult = 0;
return true;
}
_DelaySyncActiveMdiChild();
}
if( g_PaintManager.m_bIsWinXPorLater )
{
HWND hWndMdiArea = _GetHwndMdiArea();
if( nMessage == WM_MDIACTIVATE )
{
HWND hWndNew = (HWND)wParam;
BOOL bOldWasMaximized = FALSE;
HWND hWndOld = (HWND)
::SendMessage( hWndMdiArea, WM_MDIGETACTIVE, 0, (LPARAM)&bOldWasMaximized );
if( bOldWasMaximized )
{
ASSERT( ::IsZoomed( hWndOld ) );
::SendMessage( hWndMdiArea, WM_SETREDRAW, FALSE, 0 );
}
if( ::IsIconic( hWndNew ) )
::SendMessage( hWndMdiArea, WM_MDIRESTORE, (WPARAM)hWndNew, 0 );
LRESULT _lResult = CExtHookSink::OnHookWndMsgDefault();
_lResult;
if( bOldWasMaximized )
{
::SendMessage( hWndMdiArea, WM_SETREDRAW, TRUE, 0 );
::RedrawWindow( hWndMdiArea, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN );
}
return true;
}
return
CExtHookSink::OnHookWndMsg(
lResult,
hWndHooked,
nMessage,
wParam,
lParam
);
}
}
else
{
ASSERT( FALSE );
}
MSG msg;
::memset( &msg, 0, sizeof(MSG) );
msg.hwnd = hWndHooked;
msg.message = nMessage;
msg.wParam = wParam;
msg.lParam = lParam;
if( TranslateMainFrameMessage(&msg) )
return true;
return
CExtHookSink::OnHookWndMsg(
lResult,
hWndHooked,
nMessage,
wParam,
lParam
);
}
|
|
David Skok
|
Jun 1, 2006 - 6:32 AM
|
Thank you for the quick response, problem solved.
As a note for others reading this, the source to replace is in ExtMenuControlBar.cpp not ExtPopupMenuWnd.cpp
|
|