Jump to content
Tuts 4 You

How To Read Text From Labels Menus Etc..


ChupaChu

Recommended Posts

Hi there, i have a question for Delphi code.

I want to be able to read all text from other processess windows.

Now i am aware of FindWindow API, but it only reads Caption of a main form - and I want to be able to read from status bar, menus, memoboxes, from everything that might contain text.

So is there a way to get this (except capturing a screen and using ocr to recognize eventualy text)?

Any ideas, comments?

Edited by ChupaChu
Link to comment

EnumWindows might help, combined with EnumChildWindows.

GetWindow should be useful, too.

Can't provide you with example source, but MSDN should help you out :)

Link to comment

SendMessageByString API then a const VM_GETTEXT

or maybe the GetWindowText API

I could show you in VB but your using delphi, but the API's are the same i would imagine

Link to comment

here is an example to get text from Internet Explore 7 URL bar, I know this is just reading text from an edit box but its the same method for a lable control also,

Dim TheText As String, TL As Long
Dim ieframe As Long
Dim workerw As Long
Dim rebarwindow As Long
Dim addressbandroot As Long
Dim comboboxex As Long
Dim combobox As Long
Dim editx As Longieframe = FindWindow("ieframe", vbNullString)
workerw = FindWindowEx(ieframe, 0&, "workerw", vbNullString)
rebarwindow = FindWindowEx(workerw, 0&, "rebarwindow32", vbNullString)
addressbandroot = FindWindowEx(rebarwindow, 0&, "address band root", vbNullString)
comboboxex = FindWindowEx(addressbandroot, 0&, "comboboxex32", vbNullString)
combobox = FindWindowEx(comboboxex, 0&, "combobox", vbNullString)
editx = FindWindowEx(combobox, 0&, "edit", vbNullString)
TL = SendMessageLong(editx&, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(editx&, WM_GETTEXT, TL + 1, TheText)
TheText = Left(TheText, TL)

In vb you would have to declare functions

FindWindowEx
FindWindow
SendMessageLong
SendMessageByString

And declare Consts

WM_GETTEXTLENGTH = &HE
WM_GETTEXT = &HD
Edited by Departure
Link to comment
  • 3 weeks later...

yes FindWindowEx is there key here, And because I just started using delphi I have relized its nearly exactly the same with delphi Due to being API functions

Link to comment
  • 2 weeks later...

I might suggest an APISpy. A programmer's tool which is really helpful in dealing with this type of thing. It uses the getwindowfrompoint and the position of the mouse cursor so you can gather information as well as check your program's results against what the spy found.

Also know that the newer versions of windows do not allow the Sendmessage WM_GETTEXT or getwindowtext to work with edit boxes.

Link to comment

WM_GETTEXT works fine in windowsXP, I have'nt tryed it in vista but now that you have said the above I am going to investigate this further and find a solution...

Thanks for the info

Link to comment

use findwindowEX since you can set it to find child or parent windows.EnumWindows might help, combined with EnumChildWindows. as said above could also help.

http://msdn2.microsoft.com/en-us/library/ms633500.aspx

Syntax

HWND FindWindowEx(

HWND hwndParent,

HWND hwndChildAfter,

LPCTSTR lpszClass,

LPCTSTR lpszWindow

);

Parameters

hwndParent

[in] Handle to the parent window whose child windows are to be searched.

If hwndParent is NULL, the function uses the desktop window as the parent window. The function searches among windows that are child windows of the desktop.

Microsoft Windows 2000 and Windows XP: If hwndParent is HWND_MESSAGE, the function searches all message-only windows.

hwndChildAfter

[in] Handle to a child window. The search begins with the next child window in the Z order. The child window must be a direct child window of hwndParent, not just a descendant window.

If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.

Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level and message-only windows.

lpszClass

[in]

Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be placed in the low-order word of lpszClass; the high-order word must be zero.

If lpszClass is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names, or it can be MAKEINTATOM(0x800). In this latter case, 0x8000 is the atom for a menu class. For more information, see the Remarks section of this topic.

lpszWindow

[in] Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.

Return Value

If the function succeeds, the return value is a handle to the window that has the specified class and window names.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Link to comment

I have a li'l extra thing to ask here. Like, I got the handle to a specific Static label from another window.Now I want to get the property WS_VISIBLE value for this label.How can that be done?

Oricode.

Edited by oricode
Link to comment

I'm not sure there is sucha Window Message this are all i cud find in delphi:

WM_ACTIVATE
WM_ACTIVATEAPP
WM_CANCELMODE
WM_CHILDACTIVATE
WM_CLOSE
WM_COMPACTING
WM_COPYDATA
WM_CREATE
WM_DESTROY
WM_ENABLE
WM_ENTERSIZEMOVE
WM_EXITSIZEMOVE
WM_GETICON
WM_GETMINMAXINFO
WM_GETTEXT
WM_GETTEXTLENGTH
WM_INPUTLANGCHANGE
WM_INPUTLANGCHANGEREQUEST
WM_MOVE
WM_MOVING
WM_NCACTIVATE
WM_NCCALCSIZE
WM_NCCREATE
WM_NCDESTROY
WM_PARENTNOTIFY
WM_POWER
WM_QUERYDRAGICON
WM_QUERYOPEN
WM_QUIT
WM_SETICON
WM_SETTEXT
WM_SETTINGCHANGE
WM_SHOWWINDOW
WM_SIZE
WM_SIZING
WM_STYLECHANGED
WM_STYLECHANGING
WM_USERCHANGED
WM_WINDOWPOSCHANGED
WM_WINDOWPOSCHANGING
WM_WININICHANGE
Link to comment

I believe the window has to be visible to be found. I know there are other ways to manipulate this and such, but I believe if it's programatically invisible that findwindow wont find it.

Link to comment
  • 10 years later...

Hello this Api FindWindowEx .

Usually i'd use FindWindow to get handle of a specific program  by declaring like this 

var
hwnd: THandle;
begin
      hwnd:= FindWindow(nil, 'MyApp'); 

 

But doesn't work the same for FindWindowEx. Can someone give me a delphi example on how to use?

Edited by C++
Repeated words so I removed one of the repeated word
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...