我正在尝试读取活动应用程序中菜单项的标签名称并将它们存储在List<String>
.
不幸的是,dwTypeData
总是返回null
。为什么是这样?
List<string> ls = new List<string>();
IntPtr hMenu = Win32.GetMenu(hWnd);
if (hMenu.ToInt32() != 0)
{
for (int i = Win32.GetMenuItemCount(hMenu); i >= 0; i--)
{
try
{
uint MIIM_STRING = 0x00000040;
uint MFT_STRING = 0x00000000;
uint MIIM_TYPE = 0x00000010;
Win32.MENUITEMINFO mif = new Win32.MENUITEMINFO();
mif.cbSize = (uint)Marshal.SizeOf(typeof(Win32.MENUITEMINFO));
mif.fMask = MIIM_TYPE;
mif.fType = MFT_STRING;
mif.cch = 256;
mif.dwTypeData = "";
Win32.GetMenuItemInfo(hMenu, (uint)i, true, ref mif); //To load cch into memory
Win32.GetMenuItemInfo(hMenu, (uint)i, true, ref mif); //To fill dwTypeData
ls.Add(mif.dwTypeData);
}
catch { }
}
}
return ls;