Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Click the button in other application using QT
Forum Updated to NodeBB v4.3 + New Features

Click the button in other application using QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T TomNow99

    Hello,

    I would like to write application in QT which can programatically click on button in other application ( this other app can be written in other language like java or c# ). I know that is application spy++, which give me information about this button. But how can I send signal that I want click on it?

    If this is impossible in QT maybe someone know how can I write this using winapi? I try with

    HWND hwndApp =FindWindow(NULL, L"otherAppTitle");
    HWND ButtonHandle = FindWindowEx(hwndApp , NULL, NULL, L"pushButton");
    

    but I don't get proper ButtonHandle ( ButtonHandle is 0x0 ). Next I know that I can using SendMessage() function, but my goal is to get proper ButtonHandle.

    "pushButton" is the name of the QPushButton and his text.

    I try with:

    HWND top_child = GetWindow(FindWindow(NULL, L"otherAppTitle"), GW_CHILD);
    

    too. But still 0x0

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #2

    @TomNow99
    If you don't get an answer here, your question would be best raised in a Windows SDK forum.

    1 Reply Last reply
    2
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi
      I would try with https://www.autoitscript.com/site/
      and if it cant push the button. Nothing can.

      1 Reply Last reply
      2
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #4

        I try with:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include "windows.h"
        #include <QDebug>
        
        BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam)
        {
            qDebug() << "tmp message";
            return TRUE;
        }
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
            HWND hWndParent = FindWindow( NULL, L"abcde" );
            qDebug() << "address" << hWndParent;
            EnumChildWindows( hWndParent, EnumChildProc, NULL );
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        

        but with no positive result ( I don't see any child of "abcde" ).

        ex3.png

        qDebug from hWndParent is good - I get it, but no his childs ( I don't see any "tmp message" ).

        mrjjM 1 Reply Last reply
        0
        • T TomNow99

          I try with:

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include "windows.h"
          #include <QDebug>
          
          BOOL CALLBACK EnumChildProc ( HWND hwndChild, LPARAM lParam)
          {
              qDebug() << "tmp message";
              return TRUE;
          }
          
          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
              HWND hWndParent = FindWindow( NULL, L"abcde" );
              qDebug() << "address" << hWndParent;
              EnumChildWindows( hWndParent, EnumChildProc, NULL );
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          

          but with no positive result ( I don't see any child of "abcde" ).

          ex3.png

          qDebug from hWndParent is good - I get it, but no his childs ( I don't see any "tmp message" ).

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @TomNow99
          Hi
          is that a QPushbutton ?

          You have to understand if the control/button is not a native windows control, it wont have a handle and
          wont show up with EnumChildWindows

          So its not really easy to automate a Qt app from outside for instance.

          1 Reply Last reply
          1
          • T Offline
            T Offline
            TomNow99
            wrote on last edited by
            #6

            @mrjj

            Yes, this is QPushButton and this is Qt App

            But is there any solution?

            mrjjM 1 Reply Last reply
            0
            • T TomNow99

              @mrjj

              Yes, this is QPushButton and this is Qt App

              But is there any solution?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @TomNow99
              Hi
              I not seen anything that works purely from outside that can automate Qt app.

              Can you tell what goal is ?
              Maybe there is other way to archive that.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TomNow99
                wrote on last edited by TomNow99
                #8

                @mrjj

                Sometimes I would like to automate some GUI application which often don't have native windows controls. I know that some app I can control from QT ( for example excel ), but I think ( for example ) about apps to sell in a shop too, which are custom by owners of the shop.

                mrjjM 1 Reply Last reply
                0
                • T TomNow99

                  @mrjj

                  Sometimes I would like to automate some GUI application which often don't have native windows controls. I know that some app I can control from QT ( for example excel ), but I think ( for example ) about apps to sell in a shop too, which are custom by owners of the shop.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @TomNow99
                  Well for custom widgets, you cannot use win API for it.
                  Then you would have to hand code something that moves mouse to button and clicks.

                  Browsers have anti measure for this so that dont often work.
                  But for other apps it will.

                  • which are custom by owners of the shop.
                    So thats inside a browser ?
                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TomNow99
                    wrote on last edited by
                    #10

                    @mrjj Now I think about Desktop apps.

                    I thought about move mouse to button and click too. But how can I do this? Do you think about: open that dekstop app, check (x,y) mouse's position and write app to simulate clicking in this place? This is solution, but I think it is very bad. Do you know better?

                    mrjjM 1 Reply Last reply
                    0
                    • T TomNow99

                      @mrjj Now I think about Desktop apps.

                      I thought about move mouse to button and click too. But how can I do this? Do you think about: open that dekstop app, check (x,y) mouse's position and write app to simulate clicking in this place? This is solution, but I think it is very bad. Do you know better?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @TomNow99
                      Hi
                      In Qt you can use QCursor to move mouse around.

                      I used autoit and https://www.autoitscript.com/forum/files/file/471-image-search-udf/
                      to search for the button with image so if window was moved then it would still find it.
                      Its not a nice solution but i never found anything better.

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        TomNow99
                        wrote on last edited by
                        #12

                        @mrjj Thank you. I checked QCursor and it's work perfect. Can you tell me how Can I click using Qt?

                        I would like to move mouse cursor using QCursor and when cursor is above some icon with exe I would like to double click on this icon and run an exe.

                        mrjjM 1 Reply Last reply
                        0
                        • T TomNow99

                          @mrjj Thank you. I checked QCursor and it's work perfect. Can you tell me how Can I click using Qt?

                          I would like to move mouse cursor using QCursor and when cursor is above some icon with exe I would like to double click on this icon and run an exe.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #13

                          @TomNow99
                          Hi
                          I have not tried with Qt.
                          but maybe

                          #include <QTest>
                          QTest::mouseClick(d, Qt::LeftButton, Qt::NoModifier, QPoint(x,y));
                          i dont know if this works externally !

                          else its via windows api and send message

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved