PDA

View Full Version : Qt and the Win32 API: How to get text from another application?



garandou
10th April 2009, 15:28
I'd like to write a little program that reads text from an edit box in a Qt application window and inputs the text into a non-Qt application window. Both apps are running on Windows XP. If both apps were non-Qt, I'd get the text from app A using the Win32 API like this (C++):


HWND add_items;
mainwindow = FindWindow(NULL, _T("window name"));
HWND editbox;
editbox = FindWindowEx(mainwindow, NULL, _T("editbox name"), NULL);
TCHAR buf[512];
SendMessage(editbox, WM_GETTEXT, (WPARAM) sizeof(buf), (LPARAM) buf);

Pasting the text into app B is done in a similar way, only the last line sends the window message WM_SETTEXT instead of WM_GETTEXT.

Now, my problem is that this way doesn't seem work with a Qt application. Using a tool like Winspector or Spy++ to find out the class names and texts of the windows in a native Windows application like Notepad, the tool shows how the window text changes when I enter something in Notepad.

In the Qt application I can identify the edit box containing the text as a QWidget, but the window text is only "qt_viewport" and doesn't change when I change the text in the edit box, and the above way of getting or setting the text in the edit box doesn't work at all.

What's the right way to get the text?