如何声明 findwindow 函数。

类别:.NET开发 点击:0 评论:0 推荐:

[DllImport("user32.dll")]
 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 //Open Up blank Notepad First !
 string lpszParentClass = "Notepad";
 string lpszParentWindow = "Untitled - Notepad";
 string lpszClass = "Edit";


 IntPtr ParenthWnd = new IntPtr(0);
 IntPtr hWnd = new IntPtr(0);
 ParenthWnd = FindWindow(lpszParentClass,lpszParentWindow);
 if (ParenthWnd.Equals(IntPtr.Zero)) 
     Console.WriteLine("Notepad Not Running");
 else
 {
     hWnd = FindWindowEx(ParenthWnd,hWnd,lpszClass,"");
     if (hWnd.Equals(IntPtr.Zero)) 
         Console.WriteLine("What the F??? Notepad doesn't have an edit component ?");
     else
     {
         Console.WriteLine("Notepad Window: " + ParenthWnd.ToString());
         Console.WriteLine("Edit Control: " + hWnd.ToString());
     }
 }

本文地址:http://com.8s8s.com/it/it43631.htm