更新时间:2024-03-22 22:42
DrawMenuBar是一个计算机函数,功能是该函数重画指定菜单的菜单条。
如果系统创建窗口以后菜单条被修改,则必须调用此函数来画修改了的菜单条。
函数原型:BOOL DrawMenuBar(HWND hWnd);
参数:
hWnd:其菜单条需要被重画的窗口的句柄。
返回值:如果函数调用成功,返回非零值:如果函数调用失败,返回值是零。若想获得更多的错误信息,请调用GetLastError函数。
速查:Windows NT:及以上版本;Windows:95及以上版本;Windows:2.0及以上版本;头文件:winuser.h;输入库:user32.lib。
示例:
void CMainFrame::OnCwndDeletefilemenu()
{
// This example deletes the leftmost popup menu or leftmost
// popup menu item from the application's main window.
CWnd* pMain = AfxGetMainWnd();
// The main window _can_ be NULL, so this code
// doesn't ASSERT and actually tests.
if (pMain != NULL)
{
// Get the main window's menu
CMenu* pMenu = pMain->GetMenu();
// If there is a menu and it has items, we'll
// delete the first one.
if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
{
pMenu->DeleteMenu(0, MF_BYPOSITION);
// force a redraw of the menu bar
pMain->DrawMenuBar();
}
// No need to delete pMenu because it is an MFC
// temporary object.
}
}