Results 1 to 17 of 17

Thread: Using WinAPI FindWindow with Qt

  1. #1
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Using WinAPI FindWindow with Qt

    Not sure if this is the right forum or not, but thought I would try asking here.

    I have an application that I want to send messages via the WinAPI, so I need to get the HWND of some buttons and controls. I took a look at Spy++ to see how I can find the class names and captions to use with FindWindow, but it doesn't let me select the children of the main window. I only get one QWidget, which is the main window. I tried FindWindowEx to enumerate the children windows, but it doesn't report any.

    How exactly can I find these HWNDs with the WinAPI?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using WinAPI FindWindow with Qt

    Set a Qt::WA_NativeWindow attribute for each widget you want to have access to or call its QWidget::winId() method which will return you the handle (and create it before doing that).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by wysota View Post
    Set a Qt::WA_NativeWindow attribute for each widget you want to have access to or call its QWidget::winId() method which will return you the handle (and create it before doing that).
    Thanks for your reply. How would I do this when the application is a 3rd party application? My application is also in Qt, but I don't think there is anything other than the WinAPI for this kinda stuff, right?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Using WinAPI FindWindow with Qt

    J-P Nurmi

  5. #5
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by jpn View Post
    From my understanding, this is just a wrapper around the WinAPI. So I should be able to do the same thing within my own application. If I'm not able to call FindWindow to get a button's HWND, then neither can QxtWindowSystem.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using WinAPI FindWindow with Qt

    The button doesn't have a handler. If you can't rebuild the other application (or run it with Qt 4.3 or less), I'm afraid there is nothing you can do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by wysota View Post
    The button doesn't have a handler. If you can't rebuild the other application (or run it with Qt 4.3 or less), I'm afraid there is nothing you can do.
    Was afraid of that

    What about giving this a try?

    http://www.qtsoftware.com/products/a.../qtwinmigrate/

    Do you think there is anything I can do with this?

    Thanks.

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    again.. if you do not have the source .. you cant do anything

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by emostar View Post
    Was afraid of that

    What about giving this a try?

    http://www.qtsoftware.com/products/a.../qtwinmigrate/

    Do you think there is anything I can do with this?

    Thanks.
    What exactly are you trying to achieve?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by wysota View Post
    What exactly are you trying to achieve?
    To get data from a 3rd party application that is written in Qt. I need to iterate what looks like a QTreeList, but the application doesn't expose these qwidget's as native windows.

    If this isn't possible with the normal WinAPI, I'm guessing I will have to go to a lower level to be able to extract this information.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using WinAPI FindWindow with Qt

    The top level window has a handler. If you're able to calculate offsets of widgets you need to access from the top level window, you can send input events there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by wysota View Post
    The top level window has a handler. If you're able to calculate offsets of widgets you need to access from the top level window, you can send input events there.
    Yes, that will work for input, but I still will have to use other means to read the text in the QTreeList, right?

  13. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Using WinAPI FindWindow with Qt

    One way could be to inject some code to Qt and run the application against your modified Qt. I assume this is the way for example Squish works.
    J-P Nurmi

  14. #14
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by jpn View Post
    One way could be to inject some code to Qt and run the application against your modified Qt. I assume this is the way for example Squish works.
    Yes, code injection or api redirection appears to be the only ways possible. And I can't tell yet if Qt is using the basic WinAPI for drawing.. it appears to be Direct3D or DirectDraw on Win platforms.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by jpn View Post
    One way could be to inject some code to Qt and run the application against your modified Qt. I assume this is the way for example Squish works.
    The easiest way would be to run the application against a Qt that doesn't support "aliens" at all. This way the application would possibly run slower but all widgets would have real handles. I'm also wondering if there is a commandline switch disabling aliens completely for an application (turning on the opengl rendering system could also do it as opengl needs real handles, as far as I remember).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using WinAPI FindWindow with Qt

    Quote Originally Posted by wysota View Post
    The easiest way would be to run the application against a Qt that doesn't support "aliens" at all. This way the application would possibly run slower but all widgets would have real handles. I'm also wondering if there is a commandline switch disabling aliens completely for an application (turning on the opengl rendering system could also do it as opengl needs real handles, as far as I remember).
    Found it. The QT_USE_NATIVE_WINDOWS environment variable must be set to a positive integer.

    I also implemented an application that injects a dll I made into the Qt application, and I am able to convert the HWND to QWidget*, cast it to the proper control and use it as necessary. The dll locks up the application when I call QMessageBox::information(), so I guess something with the event loop processing isn't working correctly.

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using WinAPI FindWindow with Qt

    You can't inject objects (such as events) into the other application because of different address spaces. The only thing you may do is to implement a "server" dll that can be instrumented from outside of the process (i.e. using a socket or a pipe) to do tasks from inside the process address space.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. FindWindow
    By sonuani in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2008, 10:37
  2. Getting QLabel to work with WinAPI GetWindowText?
    By m.parker in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2006, 21:22

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.