• 全部
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

菜单事件动态响应问题,急!!!

blackstone 华为软件 开发组长/高级工程师/技术专家  2001-08-10 12:23:31
我想在WindowProc函数中得到动态加入的菜单的ID,但菜单电击后WindowProc传入参数wParam为0的情况,有那位大虾help me?
...全文
26 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
prog_st 2001-08-10
菜单电击后变成“糊”菜单
Example

// CMainFrame::OnChangeFileMenu() is a menu command handler for
// CMainFrame class, which in turn is a CFrameWnd-derived class.
// It modifies the File menu by inserting, removing and renaming
// some menu items. Other operations include associating a context
// help id and setting default menu item to the File menu.
// CMainFrame is a CFrameWnd-derived class.
void CMainFrame::OnChangeFileMenu()
{
// Get the menu from the application window.
CMenu* mmenu = GetMenu();

// Look for "File" menu.
int pos = FindMenuItem(mmenu, "&File");
if (pos == -1)
return;

// Remove "New" menu item from the File menu.
CMenu* submenu = mmenu->GetSubMenu(pos);
pos = FindMenuItem(submenu, "&New\tCtrl+N");
if (pos > -1)
submenu->RemoveMenu(pos, MF_BYPOSITION);

// Look for "Open" menu item from the File menu. Insert a new
// menu item called "Close" right after the "Open" menu item.
// ID_CLOSEFILE is the command id for the "Close" menu item.
pos = FindMenuItem(submenu, "&Open...\tCtrl+O");
if (pos > -1)
submenu->InsertMenu(pos + 1, MF_BYPOSITION, ID_CLOSEFILE, "&Close");

// Rename menu item "Save" to "Save Selection".
pos = FindMenuItem(submenu, "&Save\tCtrl+S");
if (pos > -1)
{
UINT id = submenu->GetMenuItemID(pos);
submenu->ModifyMenu(id, MF_BYCOMMAND, id, "&Save Selection");
}

// Associate a context help ID with File menu, if one is not found.
// ID_FILE_CONTEXT_HELPID is the context help ID for the File menu
// that is defined in resource file.
if (submenu->GetMenuContextHelpId() == 0)
submenu->SetMenuContextHelpId(ID_FILE_CONTEXT_HELPID);

// Set "Open" menu item as the default menu item for the File menu,
// if one is not found. So, when a user double-clicks the File
// menu, the system sends a command message to the menu's owner
// window and closes the menu as if the File\Open command item had
// been chosen.
if (submenu->GetDefaultItem(GMDI_GOINTOPOPUPS, TRUE) == -1)
{
pos = FindMenuItem(submenu, "&Open...\tCtrl+O");
submenu->SetDefaultItem(pos, TRUE);
}
}

// FindMenuItem() will find a menu item string from the specified
// popup menu and returns its position (0-based) in the specified
// popup menu. It returns -1 if no such menu item string is found.
int FindMenuItem(CMenu* Menu, LPCTSTR MenuString)
{
ASSERT(Menu);
ASSERT(::IsMenu(Menu->GetSafeHmenu()));

int count = Menu->GetMenuItemCount();
for (int i = 0; i < count; i++)
{
CString str;
if (Menu->GetMenuString(i, str, MF_BYPOSITION) &&
(strcmp(str, MenuString) == 0))
return i;
}

return -1;

}
回复
ShyWJB 2001-08-10
响应WM_INITPOPMENU消息,所有菜单弹出前都会发送该消息,可在参数中得到ID,详见MSDN注释
回复
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2001-08-10 12:23
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……