您的位置:首页 > 其它

Something about CMenu

2009-09-04 20:04 260 查看
VOID setWindowOnMenuTopMost(HWND hWnd, int iMenu, int iPos)
{
HMENU hMenu			= GetMenu(hWnd);
HMENU hSubMenu		= GetSubMenu(hMenu, iMenu);
UINT uID			= GetMenuItemID(hSubMenu, iPos);
ASSERT( uID != -1 );
MENUITEMINFO miiTopMost;
// ZeroMemory is necessary
ZeroMemory(&miiTopMost, sizeof miiTopMost);
// fMask: Members to retrieve or set.if you want to modify fState member, just evaluate fMark member with MIIMSTATE
// The same to other members, fMask can be one or more values.
miiTopMost.fMask = MIIM_STATE;
// Fill cbSize member is necessary
miiTopMost.cbSize	= sizeof MENUITEMINFO;

// Fill MENUITEMINFO menu item information;TRUE: menu item posation, FALSE: menu item ID.
BOOL bRes = GetMenuItemInfo(hSubMenu, uID, FALSE, &miiTopMost);
ASSERT( bRes );
if( miiTopMost.fState == MFS_CHECKED )
{
// Set window no topmost, update menu information and redraw menu
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
miiTopMost.fState = MFS_UNCHECKED;
SetMenuItemInfo(hSubMenu, uID, FALSE, &miiTopMost);
DrawMenuBar(hWnd);
}
else
{
// Set window topmost, update menu information and redraw menu
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
miiTopMost.fState = MFS_CHECKED;
SetMenuItemInfo(hSubMenu, uID, FALSE, &miiTopMost);
DrawMenuBar(hWnd);
}
return ;
}


 

该函数实现功能:就是一般程序通过菜单选项选择总显示在最前端功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  menu