虽然问题幼稚但很急,请问我要动态的添加两极菜单

html007 2000-07-19 06:38:00
加精
虽然问题幼稚但很急,请问我要动态的添加两极菜单,那么我一级菜单的属性怎样设,才能使二级菜单加上。急!!!!!!!!
...全文
210 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
html007 2000-07-21
  • 打赏
  • 举报
回复
endlessway非常感谢您的热心帮忙!!我的问题解决了。
endlessway 2000-07-21
  • 打赏
  • 举报
回复
最主要的是第一个参数若是MF_POPUP,则第二个参数是一个菜单的HMENU句柄,用int转换一下
pPopmenu->AppendMenu(MF_POPUP,(int)x->m_hMenu,"popup");
endlessway 2000-07-21
  • 打赏
  • 举报
回复
CMenu Popmenu;
Popmenu.LoadMenu(IDR_MAINMENU);//主菜单
添加popup菜单的方法:
CMenu Popmenu;
Popmenu.LoadMenu(IDR_MAINMENU);//主菜单
CMenu popmenu2;
popmenu2.LoadMenu(IDR_MENU1);//将要添加的popup菜单,此处是从资源得到,可以在程序中自己CreateMenu
CMenu *x=popmenu2.GetSubMenu(0);
CMenu* pPopmenu= Popmenu.GetSubMenu(0);//一级菜单
pPopmenu->AppendMenu(MF_POPUP,(int)x->m_hMenu,"popup");
pPopmenu->TrackPopupMenu(TPM_LEFTALIGN ,100,100,AfxGetMainWnd(),NULL);
endlessway 2000-07-21
  • 打赏
  • 举报
回复
添加popup菜单的方法:
CMenu Popmenu;
Popmenu.LoadMenu(IDR_MAINMENU);//主菜单
CMenu popmenu2;
popmenu2.LoadMenu(IDR_MENU1);//将要添加的popup菜单,此处是从资源得到,可以在程序中自己CreateMenu
CMenu *x=popmenu2.GetSubMenu(0);
CMenu* pPopmenu= Popmenu.GetSubMenu(0);//一级菜单
pPopmenu->AppendMenu(MF_POPUP,(int)x->m_hMenu,"popup");
pPopmenu->TrackPopupMenu(TPM_LEFTALIGN ,100,100,AfxGetMainWnd(),NULL);
html007 2000-07-20
  • 打赏
  • 举报
回复
endlessway你说得很对,我的程序如下请指点
Popmenu.LoadMenu(IDR_MAINMENU);//主菜单
CMenu* pPopmenu= Popmenu.GetSubMenu(0);//一级菜单
pPopmenu->InsertMenu(0,MF_POPUP,123,(pNewsType+i)->NewsType); ///加条目
CMenu* w=pPopmenu->GetSubMenu(0)->GetSubMenu(0);//得不到下级菜单了
endlessway 2000-07-20
  • 打赏
  • 举报
回复
在将菜单的pop-up属性选择后,必须为这个popup菜单添加至少一个子菜单
例如: RecentFile->NoRecentFile RecentFile是popup菜单,NoRecentFile只是添加,不做处理,以后添加了菜单,可以再将NoRecentFile删除,但必须至少有一个子菜单
// MenuBar 一级菜单 二级菜单
CMenu *pMenu=AfxGetMainWnd()->GetMenu()->GetSubMenu(4)->GetSubMenu(3);
pMenu->AppendMenu(MF_STRING,60000,"New MenuItem1");
html007 2000-07-20
  • 打赏
  • 举报
回复
不管用,那位有demo程序?????????????
endlessway 2000-07-19
  • 打赏
  • 举报
回复
pop-up属性选择上就可以增加二级菜单
WHQ 2000-07-19
  • 打赏
  • 举报
回复
用AppendMenu
The AppendMenu function appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu. You can use this function to specify the content, appearance, and behavior of the menu item.

The AppendMenu function has been superseded by the InsertMenuItem function. You can still use AppendMenu, however, if you do not need any of the extended features of InsertMenuItem.

BOOL AppendMenu(

HMENU hMenu, // handle to menu to be changed
UINT uFlags, // menu-item flags
UINT uIDNewItem, // menu-item identifier or handle of drop-down menu or submenu
LPCTSTR lpNewItem // menu-item content
);


Parameters

hMenu

Identifies the menu bar, drop-down menu, submenu, or shortcut menu to be changed.

uFlags

Specifies flags to control the appearance and behavior of the new menu item. This parameter can be a combination of the values listed in the following Remarks section.

uIDNewItem

Specifies either the identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, the handle to the drop-down menu or submenu.

lpNewItem

Specifies the content of the new menu item. The interpretation of lpNewItem depends on whether the uFlags parameter includes the MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag, as follows:

Value Description
MF_BITMAP Contains a bitmap handle.
MF_OWNERDRAW Contains a 32-bit value supplied by the application that can be used to maintain additional data related to the menu item. The value is in the itemData member of the structure pointed to by the lparam parameter of the WM_MEASURE or WM_DRAWITEM message sent when the menu is created or its appearance is updated.
MF_STRING Contains a pointer to a null-terminated string.


Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The application must call the DrawMenuBar function whenever a menu changes, whether or not the menu is in a displayed window.
The following flags can be set in the uFlags parameter:

Value Description
MF_BITMAP Uses a bitmap as the menu item. The lpNewItem parameter contains the handle to the bitmap.
MF_CHECKED Places a check mark next to the menu item. If the application provides check-mark bitmaps (see SetMenuItemBitmaps), this flag displays the check mark bitmap next to the menu item.
MF_DISABLED Disables the menu item so it cannot be selected, but the flag does not gray it.
MF_ENABLED Enables the menu item so it can be selected, and restores it from its grayed state.
MF_GRAYED Disables the menu item and grays it so it cannot be selected.
MF_MENUBARBREAK Functions the same as the MF_MENUBREAK flag for a menu bar. For a drop-down menu, submenu, or shortcut menu, the new column is separated from the old column by a vertical line.
MF_MENUBREAK Places the item on a new line (for a menu bar) or in a new column (for a drop-down menu, submenu, or shortcut menu) without separating columns.
MF_OWNERDRAW Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the window procedure of the owner window whenever the appearance of the menu item must be updated.
MF_POPUP Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies the handle to the drop-down menu or submenu. This flag is used to add a menu name to a menu bar, or a menu item that opens a submenu to a drop-down menu, submenu, or shortcut menu.
MF_SEPARATOR Draws a horizontal dividing line. This flag is used only in a drop-down menu, submenu, or shortcut menu. The line cannot be grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
MF_STRING Specifies that the menu item is a text string; the lpNewItem parameter points to the string.
MF_UNCHECKED Does not place a check mark next to the item (default). If the application supplies check-mark bitmaps (see SetMenuItemBitmaps), this flag displays the unchecked bitmap next to the menu item.


The following groups of flags cannot be used together:

?MF_DISABLED, MF_ENABLED, and MF_GRAYED
?MF_BITMAP, MF_STRING, and MF_OWNERDRAW
?MF_MENUBARBREAK and MF_MENUBREAK
?MF_CHECKED and MF_UNCHECKED

16,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧