首先进行声明:
[DllImport("USER32.dll", EntryPoint = "GetMenuItemCount", CharSet = CharSet.Unicode)]
private static extern int apiGetMenuItemCount(IntPtr hMenu);
然后我再类里面定义了一个菜单,并给它添加了一系列菜单项:
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.sfToolStripMenuItem,
this.sdfToolStripMenuItem,
this.sdfToolStripMenuItem1});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(95, 70);
最后调用API方法获得它的菜单项的数目并显示:
MessageBox.Show(apiGetMenuItemCount(this.contextMenuStrip1.Handle).ToString());
为什么最后显示的结果为-1?
到网上找了,但好像都是用它来操作系统菜单的,可是我想知道怎么操作普通菜单?
这段代码错在哪里,希望大家能给点指点,谢谢!
[DllImport("USER32.dll", EntryPoint = "GetMenuItemCount", CharSet = CharSet.Unicode)]
private static extern int apiGetMenuItemCount(IntPtr hMenu);
然后我再类里面定义了一个菜单,并给它添加了一系列菜单项:
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.sfToolStripMenuItem,
this.sdfToolStripMenuItem,
this.sdfToolStripMenuItem1});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(95, 70);
最后调用API方法获得它的菜单项的数目并显示:
MessageBox.Show(apiGetMenuItemCount(this.contextMenuStrip1.Handle).ToString());
为什么最后显示的结果为-1?
到网上找了,但好像都是用它来操作系统菜单的,可是我想知道怎么操作普通菜单?
这段代码错在哪里,希望大家能给点指点,谢谢!
下拉菜单也不行
我用IsMenu试了下,返回false,在API看来我拖的这个菜单根本就不是菜单
这个问题应该不难吧各位高手帮忙解决下困惑。。谢谢了!!!
public static extern Int32 GetMenuItemCount(IntPtr hMenu);
IntPtr hMenu = GetSystemMenu(this.Handle, 0);
UInt32 menuItemCount = GetMenuItemCount(hMenu);