i'm getting nut's

i just want to read out the text-string from a sub menu-item...
here's my code, sorry i know you all hate c but i don't have masm
installed on this computer...



HWND hwnd = insert window handle here

char menu_string[260];
HMENU m_handle;
HMENU sm_handle;
int item_index;
MENUITEMINFO menu_item;

// get main menu handle
m_handle = GetMenu(hwnd);

// init menu
SendMessage(hwnd, WM_INITMENU, (WPARAM)m_handle, 0);

// get first sub-menu (File->drop-down list)
sm_handle = GetSubMenu(m_handle, 0);

// init sub menu
SendMessage (hwnd, WM_INITMENUPOPUP, (WPARAM)sm_handle, 0x0000);

// get number of elements
item_index = GetMenuItemCount(sm_handle);

// get first entry
ZeroMemory(&menu_item,sizeof(menu_item));
menu_item.fMask = MIIM_TYPE;
menu_item.fType = MFT_STRING;
menu_item.dwTypeData = menu_string;
menu_item.cch= 260;
menu_item.cbSize= sizeof(menu_item);

GetMenuItemInfo(sm_handle,0,TRUE, &menu_item);


on almost every menu the first menu entry is called "File", if you
click on this item, a sub-menu will occour, in the most cases the
caption of the first item is "New", so i just want to read out THIS
item - so what the hell is wrong with my code?

hopefully somebody can help me out here, thanks in advance...
Posted on 2003-08-20 11:35:28 by mob
Hi,

to retrieve the text in the menu item I'd rather use the
flag combination: MIIM_DATA | MIIM_TYPE.

What happened? What does GetMenuItemInfo() return?



BOOL fResult ;
MENUITEMINFO xInfo ;
char szText[128] ;

xInfo.cbSize = sizeof (MENUITEMINFO) ;
xInfo.fMask = MIIM_DATA | MIIM_TYPE ;
xInfo.fType = 0 ;
xInfo.fState = 0 ;
xInfo.wID = 0 ;
xInfo.hSubMenu = NULL ;
xInfo.hbmpChecked = NULL ;
xInfo.hbmpUnchecked = NULL ;
xInfo.dwItemData = 0 ;
xInfo.dwTypeData = &szText ;
xInfo.cch = 128 ;

fResult = GetMenuItemInfo (hmenuMain, dwID, FALSE, &xInfo) ;

if (fResult && (xInfo.fType & MFT_STRING))
{
lstrcpyn (lpszOut, szText, dwMax > 128 ? 128 : dwMax) ;
}




Bye Miracle
Posted on 2003-08-22 04:01:26 by miracle