Posted October 5, 200717 yr 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, 200717 yr by ChupaChu
October 5, 200717 yr EnumWindows might help, combined with EnumChildWindows. GetWindow should be useful, too. Can't provide you with example source, but MSDN should help you out
October 5, 200717 yr Author I am not shure, but are not EnumChildWindows and rest of it just to get caption of windows (not for labels, menus etc.?)
October 5, 200717 yr 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
October 5, 200717 yr Author I know some VB, please provide an example, i will try to adjust it to fit in delphi
October 6, 200717 yr 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, 200717 yr by Departure
October 10, 200717 yr Author Thanks i think i can use this.. its pretty powerfull trick, if you apply it smartly Edited October 10, 200717 yr by ChupaChu
October 27, 200717 yr 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
November 8, 200717 yr 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.
November 8, 200717 yr 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
November 8, 200717 yr 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.
November 11, 200717 yr 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, 200717 yr by oricode
November 11, 200717 yr Author 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
November 11, 200717 yr 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.
November 12, 200717 yr no the control does'nt need to be visable... Im sure about the propertys of WM_VISIBLE to find if its visable or not...
November 12, 200717 yr Aha, I believe this may help:iswindowvisible API. On MSDN here:http://msdn2.microsoft.com/en-us/library/ms633530.aspx
January 27, 20187 yr 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, 20187 yr by C++ Repeated words so I removed one of the repeated word
January 28, 20187 yr 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
January 29, 20187 yr 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
Create an account or sign in to comment