[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr FindWindow(string strclassName, string strWindowName); private void button1_Click(object sender, System.EventArgs e)
{
IntPtr o = FindWindow(null, this.Text);
}

解决方案 »

  1.   

    http://blog.csdn.net/ncucf/archive/2004/08/03/59579.aspx
    看看这个!
      

  2.   

    IntPtr o = FindWindow(null, "notepad");
    =================================
    怎么知道我的程序已经找到了 这个记事本窗口了呢?
      

  3.   

    如果 o不等于空,就说明找到了符合条件的窗口了!
    =====================================================
    if(oo==null)运算符“==”无法应用于“System.IntPtr”和“<null>”类型的操作数
      

  4.   

    [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());
         }
     }
      

  5.   

    英文版系统用;
    string lpszParentWindow = "Untitled - Notepad";中文斑的是:string lpszParentWindow = "无标题 - 记事本";测试前先开一个空的记事本!!!
      

  6.   

    问题是你找到了这个窗口的句柄后想要做什么,比如想关闭,想改变标题,想发给其消息等,这些在.NET中默认是不提供的,你最好你声明FindWindow这个函数一样声明其它操作窗口的API,这样才能按找到的句柄对其进行操作.
    比如SendMessage, SetWindowText, GetWindowText, DestroyWindow, SetWindowExt, SetWindowPos等等有好.
      

  7.   


    声明:
    [DllImport("user32.dll", EntryPoint="FindWindow")]
    public static extern int FindWindow (
    string lpClassName,
    string lpWindowName
    );
      

  8.   

    关于SendMessage的使用,谁能讲一下。我也一直用不好。
      

  9.   

    [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());
         }
     }
    是我想要的答案。但是上面的程序需要事先 声明FindWindowEx函数。
    谢谢  BearRui(我有点笨,但我很特别,所以我特别笨!) 。。
      

  10.   

    但是上面的程序需要事先 声明FindWindowEx函数。
    -----------------------------------------------
    在C#中使用任何API都是要先声明,不然无法使用。