怎么在获取第三方的窗口下button句柄后自动执行
1个回答
2017-05-06 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Auto)]
extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[STAThread]
static void Main(string[] args)
{
string path = "..\\..\\..\\AUT3\\bin\\Debug\\AUT3.exe";
Process p = Process.Start(path);
if (p==null)
Console.WriteLine("Warning:process may already exist");
Console.WriteLine("Finding main window handle");
IntPtr mwh = FindMainWindowHandle("Form1", 100, 25);
Console.WriteLine("Handle to main window is " + mwh);
//有名字控件句柄
Console.WriteLine("Findding handle to textbox1");
IntPtr tb = FindWindowEx(mwh, IntPtr.Zero, null, "<enter color>");
if (tb == IntPtr.Zero)
throw new Exception("Unable to find textbox1");
else
Console.WriteLine("Handle to textbox1 is " + tb);
Console.WriteLine("Findding handle to button1");
IntPtr butt = FindWindowEx(mwh, IntPtr.Zero, null, "button1");
if (butt == IntPtr.Zero)
throw new Exception("Unable to find button1");
else
Console.WriteLine("Handle to button1 is " + butt);
static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Auto)]
extern static IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[STAThread]
static void Main(string[] args)
{
string path = "..\\..\\..\\AUT3\\bin\\Debug\\AUT3.exe";
Process p = Process.Start(path);
if (p==null)
Console.WriteLine("Warning:process may already exist");
Console.WriteLine("Finding main window handle");
IntPtr mwh = FindMainWindowHandle("Form1", 100, 25);
Console.WriteLine("Handle to main window is " + mwh);
//有名字控件句柄
Console.WriteLine("Findding handle to textbox1");
IntPtr tb = FindWindowEx(mwh, IntPtr.Zero, null, "<enter color>");
if (tb == IntPtr.Zero)
throw new Exception("Unable to find textbox1");
else
Console.WriteLine("Handle to textbox1 is " + tb);
Console.WriteLine("Findding handle to button1");
IntPtr butt = FindWindowEx(mwh, IntPtr.Zero, null, "button1");
if (butt == IntPtr.Zero)
throw new Exception("Unable to find button1");
else
Console.WriteLine("Handle to button1 is " + butt);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询