ChupaChu Posted October 5, 2007 Posted October 5, 2007 (edited) 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 October 5, 2007 by ChupaChu
Killboy Posted October 5, 2007 Posted October 5, 2007 EnumWindows might help, combined with EnumChildWindows. GetWindow should be useful, too. Can't provide you with example source, but MSDN should help you out
ChupaChu Posted October 5, 2007 Author Posted October 5, 2007 I am not shure, but are not EnumChildWindows and rest of it just to get caption of windows (not for labels, menus etc.?)
Departure Posted October 5, 2007 Posted October 5, 2007 SendMessageByString API then a const VM_GETTEXTor maybe the GetWindowText APII could show you in VB but your using delphi, but the API's are the same i would imagine
ChupaChu Posted October 5, 2007 Author Posted October 5, 2007 I know some VB, please provide an example, i will try to adjust it to fit in delphi
Departure Posted October 6, 2007 Posted October 6, 2007 (edited) 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 LongDim ieframe As LongDim workerw As LongDim rebarwindow As LongDim addressbandroot As LongDim comboboxex As LongDim combobox As LongDim 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 functionsFindWindowExFindWindowSendMessageLongSendMessageByStringAnd declare ConstsWM_GETTEXTLENGTH = &HEWM_GETTEXT = &HD Edited October 6, 2007 by Departure
ChupaChu Posted October 10, 2007 Author Posted October 10, 2007 (edited) Thanks i think i can use this.. its pretty powerfull trick, if you apply it smartly Edited October 10, 2007 by ChupaChu
Departure Posted October 27, 2007 Posted October 27, 2007 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
Pimp.exe Posted November 8, 2007 Posted November 8, 2007 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.
Departure Posted November 8, 2007 Posted November 8, 2007 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
StreamLine Posted November 8, 2007 Posted November 8, 2007 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.aspxSyntax 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.
oricode Posted November 11, 2007 Posted November 11, 2007 (edited) 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 November 12, 2007 by oricode
ChupaChu Posted November 11, 2007 Author Posted November 11, 2007 I'm not sure there is sucha Window Message this are all i cud find in delphi:WM_ACTIVATEWM_ACTIVATEAPPWM_CANCELMODEWM_CHILDACTIVATEWM_CLOSEWM_COMPACTINGWM_COPYDATAWM_CREATEWM_DESTROYWM_ENABLEWM_ENTERSIZEMOVEWM_EXITSIZEMOVEWM_GETICONWM_GETMINMAXINFOWM_GETTEXTWM_GETTEXTLENGTHWM_INPUTLANGCHANGEWM_INPUTLANGCHANGEREQUESTWM_MOVEWM_MOVINGWM_NCACTIVATEWM_NCCALCSIZEWM_NCCREATEWM_NCDESTROYWM_PARENTNOTIFYWM_POWERWM_QUERYDRAGICONWM_QUERYOPENWM_QUITWM_SETICONWM_SETTEXTWM_SETTINGCHANGEWM_SHOWWINDOWWM_SIZEWM_SIZINGWM_STYLECHANGEDWM_STYLECHANGINGWM_USERCHANGEDWM_WINDOWPOSCHANGEDWM_WINDOWPOSCHANGING WM_WININICHANGE
Pimp.exe Posted November 11, 2007 Posted November 11, 2007 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.
Departure Posted November 12, 2007 Posted November 12, 2007 no the control does'nt need to be visable... Im sure about the propertys of WM_VISIBLE to find if its visable or not...
Pimp.exe Posted November 12, 2007 Posted November 12, 2007 Aha, I believe this may help:iswindowvisible API. On MSDN here:http://msdn2.microsoft.com/en-us/library/ms633530.aspx
oricode Posted November 12, 2007 Posted November 12, 2007 Yup! This was what I was looking out for. Thanks.Oricode.
C++ Posted January 27, 2018 Posted January 27, 2018 (edited) 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 January 27, 2018 by C++ Repeated words so I removed one of the repeated word
Hero Posted January 28, 2018 Posted January 28, 2018 6 hours ago, C++ said: Can someone give me a delphi example on how to use? hwnd := FindWindowEx(0,0,0,'MyApp'); https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx 1
C++ Posted January 29, 2018 Posted January 29, 2018 On 1/27/2018 at 11:56 PM, Hero said: hwnd := FindWindowEx(0,0,0,'MyApp'); https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx Thanks. Now I understand
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now