public static void FindMenuTextAndID(int menuHnd, int wID, ref int posFound, ref int handleFound) { MENUITEMINFO menuinfo = new MENUITEMINFO(); menuinfo.cbSize = 44; int menuLen = GetMenuItemCount(menuHnd); for (int thisMenu = 0; thisMenu < menuLen; thisMenu++) { menuinfo.fMask = MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE | MIIM_CHECKMARKS; int di = GetMenuItemInfo(menuHnd, thisMenu, 1, ref menuinfo); if (menuinfo.wID == wID) { posFound = thisMenu; handleFound = menuHnd; } int menuID = thisMenu; FindMenuTextAndID(GetSubMenu(menuHnd, menuID), wID, ref posFound, ref handleFound); } //for return; }
public static extern int GetMenuItemInfo(int hMenu, int un, int b, [MarshalAs(UnmanagedType.Struct)] ref MENUITEMINFO lpMenuItemInfo);