用 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层

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM