In the WM_MDISETMENU handler use an existing frame menu if the passed

value is 0.
Visio expects that separator in the Window menu has ID 0.
Cope with a destroyed menu handle in WM_MDIREFRESHMENU handler.
This commit is contained in:
Dmitry Timoshkov 2004-01-26 20:14:59 +00:00 committed by Alexandre Julliard
parent 8941c0bc05
commit b9e56b9b99
1 changed files with 25 additions and 13 deletions

View File

@ -320,9 +320,10 @@ static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
MDI_RefreshMenu(ci);
}
else
{
ci->hWindowMenu = hmenuWindow;
ci->add_pos = GetMenuItemCount(hmenuWindow);
ci->hWindowMenu = hmenuWindow;
}
}
if (hmenuFrame)
@ -341,8 +342,12 @@ static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
}
else
{
INT nItems = GetMenuItemCount(ci->hFrameMenu) - 1;
UINT iId = GetMenuItemID(ci->hFrameMenu, nItems);
INT nItems;
UINT iId;
ci->hFrameMenu = GetMenu(hwndFrame);
nItems = GetMenuItemCount(ci->hFrameMenu) - 1;
iId = GetMenuItemID(ci->hFrameMenu, nItems);
if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
{
@ -365,7 +370,6 @@ static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
*/
static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
{
HMENU hFrameMenu;
UINT i, count, visible;
WCHAR buf[MDI_MAXTITLELENGTH];
@ -374,6 +378,12 @@ static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
if (!ci->hWindowMenu)
return 0;
if (!IsMenu(ci->hWindowMenu))
{
WARN("Window menu handle %p is no more valid\n", ci->hWindowMenu);
return 0;
}
count = GetMenuItemCount(ci->hWindowMenu);
for (i = ci->add_pos; i < count; i++)
RemoveMenu(ci->hWindowMenu, ci->add_pos, MF_BYPOSITION);
@ -393,7 +403,8 @@ static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
if (IsWindowVisible(ci->child[i]))
{
if (!visible)
AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, -1, NULL);
/* Visio expects that separator has id 0 */
AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, 0, NULL);
visible++;
@ -403,6 +414,7 @@ static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
buf[1] = '0' + visible;
buf[2] = ' ';
InternalGetWindowText(ci->child[i], buf + 3, sizeof(buf)/sizeof(WCHAR) - 3);
TRACE("Adding %u %s\n", id, debugstr_w(buf));
AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
if (ci->child[i] == ci->hwndActiveChild)
@ -410,9 +422,7 @@ static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
}
}
hFrameMenu = ci->hFrameMenu;
return (LRESULT)hFrameMenu;
return (LRESULT)ci->hFrameMenu;
}
@ -482,6 +492,8 @@ static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
{
UINT i;
TRACE("# of managed children %u\n", ci->nActiveChildren);
if( child == ci->hwndActiveChild )
{
MDI_SwitchActiveChild(parent, child, TRUE);
@ -510,19 +522,19 @@ static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
HeapFree(GetProcessHeap(), 0, ci->child);
ci->child = new_child;
ci->nActiveChildren--;
break;
}
}
ci->nActiveChildren--;
TRACE("child destroyed - %p\n",child);
if (flagDestroy)
{
MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
DestroyWindow(child);
}
TRACE("child destroyed - %p\n", child);
return 0;
}