MDI and SDI
How to list currently open MDI windows in the Window menu?
Just invoke the CExtMenuControlBar::SetMdiWindowPopupName method. As its argument you need to specify a name of the top level menu item whose pop-up menu should contain a list of the currently open MDI windows: m_wndMenuBar.SetMdiWindowPopupName( _T("Window") );
This can be done in the CMailFrame::OnCreate() method.
I want to add the "Windows..." dialog to my MDI application. How to do this correctly?
To insert the Windows… command that opens the dialog with a list of the currently open MDI windows, add a handler for the CExtPopupMenuWnd::g_nMsgPrepareMenu message in which you need to add a new menu item, e.g. specified with ID_WINDOWS_LIST . This code may look like: LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam)
{
wParam;
lParam;
#if (defined _AFXDLL && !defined __STATPROFUIS_WITH_DLLMFC__)
////////////////////////////////////////////////////////
// Add "Windows..." command
////////////////////////////////////////////////////////
CExtPopupMenuWnd::MsgPrepareMenuData_t * pData =
reinterpret_cast
< CExtPopupMenuWnd::MsgPrepareMenuData_t * >
( wParam );
ASSERT( pData != NULL );
CExtPopupMenuWnd * pPopup = pData->m_pPopup;
ASSERT( pPopup != NULL );
INT nItemPos;
INT nNewPos = -1;
nItemPos = pPopup->ItemFindPosForCmdID( __ID_MDIWND_DLGWINDOWS );
if( nItemPos >= 0 )
{
// "More Windows..." command found
pPopup->ItemRemove( nItemPos );
nNewPos = nItemPos;
}
else
{
int nMaxCmdID = 0;
for( int nCmdID = __ID_MDIWNDLIST_FIRST;
nCmdID <= __ID_MDIWNDLIST_LAST;
nCmdID++
)
{
nItemPos = pPopup->ItemFindPosForCmdID( nCmdID );
if( nItemPos > 0 )
{
if( nCmdID > nMaxCmdID )
{
nMaxCmdID = nCmdID;
nNewPos = nItemPos;
}
}
}
if( nNewPos > 0 )
{
pPopup->ItemInsert(
(UINT)CExtPopupMenuWnd::TYPE_SEPARATOR,
++nNewPos
);
nNewPos++;
}
}
if( nNewPos > 0 )
{
UINT nCmdID = ID_WINDOWS_LIST;
CExtCmdItem * pCmdItem =
g_CmdManager->CmdGetPtr(
g_CmdManager->ProfileNameFromWnd(
this->GetSafeHwnd()
),
nCmdID
);
if( pCmdItem == NULL ){
pCmdItem =
g_CmdManager->CmdAllocPtr(
g_CmdManager->ProfileNameFromWnd(
this->GetSafeHwnd()
),
nCmdID
);
}
ASSERT( pCmdItem != NULL );
if( pCmdItem != NULL )
{
CString sMoreWindows(_T("Windows..."));
CString sManageWindows(
_T("Manages the currently open windows")
);
pCmdItem->m_sMenuText = sMoreWindows;
pCmdItem->m_sToolbarText = pCmdItem->m_sMenuText;
pCmdItem->m_sTipTool = sManageWindows;
pCmdItem->m_sTipStatus = pCmdItem->m_sTipTool;
pCmdItem->StateSetBasic( true );
pPopup->ItemInsert(
nCmdID,
nNewPos,
sMoreWindows,
NULL,
m_hWnd
);
}
}
#endif // #if (defined _AFXDLL && !defined __STATPROFUIS_WITH_DLLMFC__)
return 1;
}
Then add a handler for the ID_WINDOWS_LIST command itself so that you can display the Windows... dialog: BOOL CMainFrame::OnCmdMsg(
UINT nID,
int nCode,
void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo
)
{
if( nCode == CN_COMMAND )
{
#if (defined _AFXDLL && !defined __STATPROFUIS_WITH_DLLMFC__)
#ifndef __EXT_MFC_NO_MDI_WINDOWS_LIST_DIALOG
if( nID == ID_WINDOWS_LIST )
{
CExtMdiWindowsListDlg dlg( this );
dlg.DoModal();
}
#endif // #ifndef __EXT_MFC_NO_MDI_WINDOWS_LIST_DIALOG
#endif // #if (defined _AFXDLL && !defined __STATPROFUIS_WITH_DLLMFC__)
}
return CMDIFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
How to highlight modified files with an asterisk (*) like as it is done in Visual Studio?
Create a class derived from CExtTabMdiWnd and implement the OnTabWndQueryItemText virtual method like as follows:
LPCTSTR CMyCustomTabMdiWnd::OnTabWndQueryItemText(
const CExtTabWnd::TAB_ITEM_INFO * pTii
) const
{
ASSERT_VALID( pTii );
HWND hWndMdiChild = (HWND)pTii->LParamGet();
if( hWndMdiChild == NULL
|| (! ::IsWindow(hWndMdiChild) )
)
return _T("");
CWnd * pWnd = CWnd::FromHandle( hWndMdiChild );
ASSERT( pWnd != NULL );
ASSERT_KINDOF( CMDIChildWnd, pWnd );
static CString sText( _T("") );
CDocument * pActiveDoc =
((CMDIChildWnd *)pWnd)->
GetActiveDocument();
if( pActiveDoc != NULL )
{
sText = pActiveDoc->GetTitle();
if( pActiveDoc->IsModified() )
sText += _T(" *");
}
if( sText.IsEmpty() )
pWnd->GetWindowText(sText);
return (sText.IsEmpty()) ? _T("") : LPCTSTR(sText);
}
If you have any questions, please visit our forum or contact our technical support team at support@prof-uis.com.
|