Window menu
Hi Paul –
I just went through this exercise and hacked together the following code to
display and
add a check beside the current top window. CGrayFormView is derived from
CFormView.
GetNextView is a routine to find all the active views. This varies on how one
keeps track
them. I used the OnUpdateCascade event to trigger the code, as I included
"Cascade"
and "Tile" in the &Window pulldown. Finally, I added 6 "ID_NEXT_WINDOWn" items
to the menu for placemarkers. They are deleted and replaced by active window
names
every time the pulldown occurs.
In the message map:
ON_COMMAND_EX(ID_NEXT_WINDOW1, OnNextWindow)
ON_COMMAND_EX(ID_NEXT_WINDOW2, OnNextWindow)
.
.
ON_COMMAND_EX(ID_NEXT_WINDOW6, OnNextWindow)
void CGrayFormView::OnUpdateCascade(CCmdUI* /*pCmdUI*/)
{
// TODO: Add your command update UI handler code here
CView* pView;
CString nextWinText, thisWinText;
CMenu* pMenu = m_mainFrame->GetMenu();
UINT nItems = pMenu->GetMenuItemCount();
GetParent()->GetWindowText(thisWinText); //Get this window title
CString menuString;
for (UINT nIDItem = 0; nIDItem < nItems; nIDItem++)
{
//Locate, by position, the "Window" menu item
pMenu->GetMenuString(nIDItem, menuString.GetBuffer(30), 30,
MF_BYPOSITION);
if (menuString == "&Window")
{
m_pMenu = pMenu->GetSubMenu(nIDItem); //Get CMenu object for popup
nItems = m_pMenu->GetMenuItemCount(); //Get count of items in popup
for (int i=nItems; i>2; i–) //Dump all previously added
menus items
m_pMenu->RemoveMenu(i, MF_BYPOSITION);
POSITION pos = m_pDocument->GetFirstViewPosition();
i = ID_NEXT_WINDOW1;
while (pos != NULL && i <= ID_NEXT_WINDOW6) //Get all active window
views
{
if ((pView = m_theDoc->GetNextView(pos)) != NULL)
{
ASSERT(pView->IsKindOf(RUNTIME_CLASS(CGrayFormView)));
pView->GetParent()->GetWindowText(nextWinText);
m_pMenu->AppendMenu(nextWinText == thisWinText ? MF_CHECKED : 0,
i++, nextWinText); //Append next view title
}
}
}
}
m_mainFrame->DrawMenuBar ();
}
Clicking on any of the items in the pulldown calls OnNextWindow where you add
the
code to locate and call BringWindowToTop() to BringWindowToTop. Simple.
Hope this does it for you…
Pete