现获取了一个窗口的句病,请问如何操作这个窗体的控件,窗口不是在同一个程序里.如:现在打开的"远程桌面连接"我想用C#写一个程序来控制"远程桌面连接"的窗口,向此窗口添加计算机名称,按连接按钮等等的操作请问如何实现谢谢

解决方案 »

  1.   

    使用消息 
    调用
    SendMessage
    PostMessage
      

  2.   

    果然没人答呵还是我来吧、这里就是列子。
    掉用其他窗口也是一样的。
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Diagnostics;namespace ShowNotepad
    {
    /*
    1、启动 notepad.exe “内容”
    2、改变记事本标题
    3、改变记事本内容

    */
    class Program
    {
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, string lParam);
    public const int WM_SETTEXT = 0xC;


    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
     
            public const int  GW_HWNDFIRST = 0;      
            public const int GW_HWNDLAST  = 1;       
            public const int GW_HWNDNEXT  = 2;        
            public const int GW_HWNDPREV  = 3;       
            public const int GW_OWNER  = 4;        
            public const int GW_CHILD  = 5; //这里用的这个常量、其他的根据字面意识就可以看懂了


            
    static void Main(string[] args)
    {
    Process proc = Process.Start("notepad.exe");
    IntPtr hTextBox = IntPtr.Zero;
    if(proc.WaitForInputIdle(5000))
    {

    hTextBox = GetWindow(proc.MainWindowHandle, GW_CHILD);
    if (hTextBox.Equals(IntPtr.Zero))
    {
    proc.Kill();
    throw new ApplicationException("调用出错");

    }
    SendMessage(proc.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, "设置,记事本窗口的标题");
    SendMessage(hTextBox, WM_SETTEXT, IntPtr.Zero, "设置内容\r\n2008-11-31曲滨");


    }
    }
    }
    }