zoukankan      html  css  js  c++  java
  • 用 c 调用 win-api 实现自动点击c# winform 程序 的按钮

    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层

  • 相关阅读:
    windows wmi
    python编码规范
    gogs安装
    mariadb-5.5安装
    python kafka
    delimiter关键字
    phpstorm设置背景图片
    linux 下mysql 关闭 启动
    通过下载git包来安装git
    git clone 某个链接时候报错Initialized empty Git repository in 不能克隆
  • 原文地址:https://www.cnblogs.com/lthxk-yl/p/7411620.html
Copyright © 2011-2022 走看看