首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# 获得窗口句柄?解决方案

2012-03-07 
C# 获得窗口句柄??[DllImport(user32.dll, EntryPoint FindWindow, SetLastError true)]//获取主

C# 获得窗口句柄??

[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]//获取主窗口句柄
  public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "D:\\uu.exe"  
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();

IntPtr hWnd1 = FindWindow("Afx:00400000:8:00010011:00000000:03F10A01", "μVision4");

我先打开需要控制的软件,用spy获得窗体类名和窗口名,然后再关闭,运行程序,为什么调试下来,句柄hwnd1总为0??求高手,而且发现窗体类名每次都不一样

[解决办法]
可能是那个 u 特殊字符造成的。

你可以用 EnumWindows API 枚举所有窗口,再找出你要的那个。

热点排行