问题描述
代码如下,目的是获取menustrip的句柄,通过FindWind找到主窗口句柄后,主窗口句柄获取无误,再通过GetMenu想取得menuStrip的句柄,但是总是返回0,想知道错在哪里了?usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Runtime.InteropServices;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacetemp{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}//获取菜单[DllImport("user32.dll")]staticexternIntPtrGetMenu(IntPtrhwnd);//获取子菜单[DllImport("user32.dll")]staticexternIntPtrGetSubMenu(IntPtrhMenu,intnPos);//获取菜单选项ID[DllImport("user32.dll")]staticexternintGetMenuItemID(IntPtrhMenu,intnPos);[DllImport("user32.dll",EntryPoint="FindWindow",CharSet=CharSet.Auto)]staticexternIntPtrFindWindow(stringlpClassName,stringlpWindowName);[DllImport("user32.dll")]staticexternIntPtrGetSystemMenu(IntPtrhwnd,boolflag);privatevoidbutton1_Click(objectsender,EventArgse){//...//mwh:mainwindowhandleIntPtrmwh=FindWindow(null,"Form1");Thread.Sleep(1000);mwh=FindWindow(null,"Form1");IntPtrhMainMenu=GetSystemMenu(mwh,false);Thread.Sleep(1000);hMainMenu=GetMenu(mwh);IntPtrhFile=GetSubMenu(hMainMenu,0);intiExit=GetMenuItemID(hFile,1);textBox1.Text=hMainMenu.ToString();//...}}}
解决方案
本帖最后由 king8569 于 2015-06-09 00:07:17 编辑
解决方案二:
同样的问题。顶