Click to See Complete Forum and Search --> : creating menu items


nbobby
March 24th, 2004, 03:13 AM
hi All.
this is my first message in this forum .hope anybody there will help me out.

i want to create menu items in a drop down button that i have created in my toolbar

please let me know how to create .

Thanx a lot in advance

bobby

clife
March 25th, 2004, 01:29 AM
HMENU hMenu;
hMenu=CreateMenu(VOID);

BOOL AppendMenu(
HMENU hMenu, // handle to menu
UINT uFlags, // menu-item options
UINT_PTR uIDNewItem, // identifier, menu, or submenu
LPCTSTR lpNewItem // menu-item content
);

then,
BOOL TrackPopupMenu(
HMENU hMenu, // handle to shortcut menu
UINT uFlags, // options
int x, // horizontal position
int y, // vertical position
int nReserved, // reserved, must be zero
HWND hWnd, // handle to owner window
CONST RECT *prcRect // ignored
);

nbobby
March 27th, 2004, 02:45 AM
hi
thanx for the reply
i have as u have told
im giving u my code below.
im trying create a popupmenu with different menuitems in it on click of my toolbar button.

my code is


LPCTSTR str = "Menu1";
HMENU hMenu;
CMenu menuPopup;
hMenu=CreatePopupMenu();

UINT in = GetMenuItemID(hMenu,0); // for getting the menuid of the first menuitem in the popup menu

AppendMenu(
hMenu, // handle to menu
MF_ENABLED, // menu-item options
in, // identifier, menu, or submenu
str // menu-item content
);

TrackPopupMenu(
hMenu, // handle to shortcut menu
TPM_LEFTALIGN | TPM_RIGHTBUTTON, // options
100, // horizontal position
200, // vertical position
0, // reserved, must be zero
wnd, // handle to owner window
NULL // ignored
);

the problem is that the program runs fine but does not show the popup menu.
please help me out as im new to the menu concept

thanx a lot in advance

Sam Hobbs
March 27th, 2004, 06:13 PM
I tried your code and it works for me. So the problem is how you are using the code or something outside else that is in the rest of your code.

Sam Hobbs
March 27th, 2004, 11:30 PM
Originally posted by nbobby
hi
thanx for the reply
i have as u have told
im giving u my code below.
im trying create a popupmenu with different menuitems in it on click of my toolbar button.

my code is


LPCTSTR str = "Menu1";
HMENU hMenu;
CMenu menuPopup;
hMenu=CreatePopupMenu();

UINT in = GetMenuItemID(hMenu,0); // for getting the menuid of the first menuitem in the popup menu

AppendMenu(
hMenu, // handle to menu
MF_ENABLED, // menu-item options
in, // identifier, menu, or submenu
str // menu-item content
);

TrackPopupMenu(
hMenu, // handle to shortcut menu
TPM_LEFTALIGN | TPM_RIGHTBUTTON, // options
100, // horizontal position
200, // vertical position
0, // reserved, must be zero
wnd, // handle to owner window
NULL // ignored
);

the problem is that the program runs fine but does not show the popup menu.
please help me out as im new to the menu concept

thanx a lot in advance I see you are have a CMenu object that you are not using. I assume you are using MFC so you should use the CMenu object.

Regardlous of that, I don't see what the value of the GetMenuItemID is; I think it is not needed.

Are you sure you have the correct window handle (wnd)?