c#如何使用user32 dll处理特定窗口

如何使用用户32 .dll处理特定窗口? 我在c#工作。 谢谢。 有人可以给我一个简短的例子吗:)我很感激! (方法:getwindowtext,show window,enumwindowcallback normal)。

试试以下,

// For Windows Mobile, replace user32.dll with coredll.dll [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); // Find window by Caption only. Note you must pass IntPtr.Zero as the first parameter. [DllImport("user32.dll", EntryPoint="FindWindow", SetLastError = true)] static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName); // You can also call FindWindow(default(string), lpWindowName) or FindWindow((string)null, lpWindowName) 

编辑:您可以使用以下声明

  // Find window by Caption public static IntPtr FindWindow(string windowName) { var hWnd = FindWindow(windowName, null); return hWnd; } 

编辑:2这是代码的简明版本:

  public class WindowFinder { // For Windows Mobile, replace user32.dll with coredll.dll [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); public static IntPtr FindWindow(string caption) { return FindWindow(String.Empty, caption); } }