迭代窗口/模拟点击按钮

#include <iostream>
#include <fstream>
#include <math.h>
#include <cctype>
#include <string>
#include <windows.h>

using namespace std;

int main()
{
    //cout << "Hello world!" << endl;
    HWND hwnd = FindWindow( 0, "文件窗口"  );


    //HWND hWnd2 =  GetDlgItem( hwnd, 1001);

    char* strs = new char[ 255 ];
    HWND hWnd2 = ::FindWindowEx(hwnd,NULL,"Button",NULL);

    while ( hWnd2 )
    {
        GetWindowText( hWnd2, strs, 255 );


        cout << strs << endl;



       /* if ( strcasecmp( strs, "确定" ) == 0 ) {
            break;
        }*/

        hWnd2 = FindWindowEx( hwnd, hWnd2, "Button", NULL );
    }




    UINT nCtrlID = ::GetDlgCtrlID(hWnd2);
    ::PostMessage(hWnd2, WM_COMMAND, (WPARAM)(BN_CLICKED << 16 | nCtrlID), (LPARAM)hWnd2);
    ::PostMessage(hWnd2,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );
    ::PostMessage(hWnd2,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));
    ::PostMessage(hWnd2,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0));

    return 0;
}

你可能感兴趣的:(模拟)