首页 > Windows开发 > 详细

用 c 调用 win-api 实现自动点击c# winform 程序 的按钮

时间:2017-08-22 15:32:00      阅读:409      评论:0      收藏:0      [点我收藏+]

c# 程序界面

技术分享

 

要点击的按钮是 “Start”

 

c程序代码: 

 

#include <windows.h>
void main()
{
    HWND windowHandle = FindWindowA(NULL, "WatchDog v1.04 (2010-06-22)");   //Can’t find a proccess

    if( windowHandle ) 
    {
        HWND hwndChild = FindWindowEx(windowHandle, NULL, NULL, NULL);

        while ( hwndChild )
        {
            HWND hwndChildChild = FindWindowEx(hwndChild, NULL, NULL, L"Start");
            if(hwndChildChild)
            {
                SendMessage(hwndChildChild, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0, 0));
                Sleep(100);
                SendMessage(hwndChildChild, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
                break;
            }
            hwndChild = FindWindowEx(windowHandle, hwndChild, NULL, NULL);
        }
    }



    return;
}

 

功能简介: 

首先用 spy++ 确定 c# 程序的 caption 是 WatchDog v1.04 (2010-06-22) 

然后用spy++ 找出 button  所在的 hierachy position ,  如下图黑线包围的是一个panel , button 在panel 里面, 也就是说 ,  panel 是 mainform 的 child window , button 是 panel 的 child window ,所以代码中向下找2层

技术分享

 

用 c 调用 win-api 实现自动点击c# winform 程序 的按钮

原文:http://www.cnblogs.com/lthxk-yl/p/7411620.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!