CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Join Date
    Jul 2002
    Posts
    788

    Read window text in another window, without mosue!

    hi,

    I need to read text or control's text from another application's windows. My application is operating from background (hidden), and try to read other application's window text. Also there is no mouse used, so i believe i can't use mouse hook or SetCapture API... etc for this matter.

    So i guess i need to capture other windows' application control's text based on some supplied screen coordinates.

    In this case how to read get the windows' handle based on the coordinates?? and subsequently obtained the text?? assuming that i know the other application's name.

    Thanks.

  2. #2
    Join Date
    Sep 2002
    Posts
    924
    It depends on the type of window, but you should be able to use Spy++ to find out about the window, and window structure used in that application. Then you can use FindWindow to find the window and child windows until you get to the window containing the text you want. Then you can use SendMessage and the HWND returned from FindWindow to get the text.

    Take a look at the following thread for an example:
    get a control's ID

  3. #3
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    You could use WindowFromPoint or ChildWindowFromPoint APIs just in case.

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    I'd be interested to know why you would want to do this.

    I have found that a lot of people are asking questions such as this, and in fact they are trying to do something very unsafe in Windows.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  5. #5
    Join Date
    Jul 2002
    Posts
    788
    Originally posted by RussG1
    It depends on the type of window, but you should be able to use Spy++ to find out about the window, and window structure used in that application. Then you can use FindWindow to find the window and child windows until you get to the window containing the text you want. Then you can use SendMessage and the HWND returned from FindWindow to get the text.
    Hi RussG1,

    Here are some information about the target application window which i want to capture screen/control's text of:-

    the target application is a visual basic application and currently it only contains one main application window. The "structure" or layout of the target application(for example, where the target's area of text or control's lie) will be different depends on who i supplied my function to. I can't let him to spy on his own application and pass me all the information need in order for me to capture screen text on his application.,because he is a system integrator and i am selling my functions to him to complete the task. However, he can give me his information such as the area or control's ID of his application as parameter(s) to my function.

    I also have the possibility of launching the target application window from my own application (i don know wheather this will help in achieving my goals). What i would want is to provide functions to other party so that he can call my VC++ function to capture a predefined screen area's text on his application.

    appreciate your help.

    !!ADDitional information: The target application and my function/library is running in an unmanned environment/PC.
    Last edited by mce; April 5th, 2004 at 09:05 PM.

  6. #6
    Join Date
    Sep 2002
    Posts
    924
    These are not Html dialogs (or something similair), are they? (a web browser control, or similair?), as that would be completely different.

    As kirants stated, WindowFromPoint or ChildWindowFromPoint APIs are a possibility if you can obtain a screen coordinate that falls within the control you want to capture the text from.

    Also, if you know the ClassName and WindowName of the main application window and the control is a direct child of the main application window, you could access the control using it's Control ID, etc. You could also use EnumChildWindows to try and find the window the contains the control yourself.

    The are a few different ways to do what you want (possibly using a combination of different API calls depending on the circumstances), all depending on what information you will know ahead of time, and the possible differences between how the application might be laid out (i.e. will the control you are trying to access always be a direct child of the main window, etc?).

    It is hard for me to completlety understand what you need, as it seems strange that the end user would be using it to capture text from his own application (that they developed)? And that using the mouse is not an option (not necessarily for hooking or anything, but just to use to find a screen coordinate, etc).

  7. #7
    Join Date
    Jul 2002
    Posts
    788
    The 3rd party target window currently has only one main application window. It is a VB application.

    Now i had some simple codes to grab the text from this 3rd party windows., for beginning i just assume that the text appear in some windows controls such as static control, edit control, button text etc...

    Code:
    ....
    
    POINT point={15,18};
    HWND  mywnd=0;
    HWND mychildwnd=0;
    
    TCHAR mytext[100]={0x00};
    ::ScreenToClient(mywnd,&point);
    mywnd=::FindWindow(0,"targetWindow");
    mychildwnd=::ChildWindowFromPoint(mywnd,point);
    ::GetWindowText(mychildwnd,mytext,100);
    These code works on static controls, but not edit or button with text. I don't have any controls ID awailable from the target window as it is written with visual basic and supplied by 3rd party.
    how can i subclass it? i noted subclassdlgitem only available in mfc?

    Also, if i build the target window in VB, i can get the main window handle only, i created a label in the VB form, but i couldn't get this child window which is the label in VB. any idea??
    Last edited by mce; April 6th, 2004 at 12:59 AM.

  8. #8
    Join Date
    Jul 2003
    Posts
    116
    originally posted by mce ...

    The 3rd party target window currently has only one main application window. It is a VB application.
    ......
    These code works on static controls
    the static control on vb applications cannot be grabbed like this, i wonder how did u do that...

    when u run any spying utility like handle pickers on a VB Application the static texts are not recognised by that because they donot have any handles, i asked in CG in the VB forums about this, one of them replied that static texts in VB are drawings and are not conventional windows with handles, so no handles means how can u apply ::GetwindowText().

    as for the original question about getting the text from a window without having any information is a lil tough one, i think that the coordinate values are very vulnerable a slight change can cause errors, the supplier has to supply some other info as well to make ur job done.
    mmmm...!!! the ID thing about main window will be helpful if the window remains in the same instance if the window is closed and reopenned there are chances that ID's may differ.

    it would be a great thing if someone comes up with this thing to sort out, if the original poster solves the mystry, share it with us here as well, (even in a very diplomatic manner who knows there are "company secrets" behind.)


    cheers.
    Last edited by siawos; April 6th, 2004 at 01:48 AM.

  9. #9
    Join Date
    Jul 2002
    Posts
    788
    well, i actually mean static in VC++ program. it works for static control only. As for vb, i tried the staic label, and doesn't work.

    ok, i found some info on this, i can use WM_GETTEXT, again this doesn't work for all controls, even though it works on edit control.

    now, i really need something that works on practically every controls, be in application in VC or VB, or just any application, as long as there is a window.

    if i launch the application from my main process, will it help in accessing the application windows controls from the process that launch it???

  10. #10
    Join Date
    Jul 2002
    Posts
    788
    Originally posted by siawos
    as for the original question about getting the text from a window without having any information is a lil tough one, i think that the coordinate values are very vulnerable a slight change can cause errors, the supplier has to supply some other info as well to make ur job done.
    mmmm...!!! the ID thing about main window will be helpful if the window remains in the same instance if the window is closed and reopenned there are chances that ID's may differ.

    cheers.
    Not exactly...
    Currently i can only think of using coordinates supplied by the application developer. There have many application developers which means there are different windows., however each of them need to provide me a general set of their window information for me to grab any text or have full control of their application. I can have the option to launch their application as well.

    So i believe this make the task much easier than having zero information on the target windows. My question is what kind of general informations actually i can request from the application developer in this case to make my task simple??
    Last edited by mce; April 6th, 2004 at 02:23 AM.

  11. #11
    Join Date
    Jul 2003
    Posts
    116
    originally posted by mce...

    My question is what kind of general informations actually i can request from the application developer in this case to make my task simple??
    you would have to devise a combination of things to determine that, no single property/value will do the job there.
    possibilities cab be...

    • window class name (vulnerable)
    • ID(vulnerable)
    • heirarchical information of the window, like parents and their properties.
    • coordinate values (vulnerable)


    all of them are vulnerable but be a bit manager sorta person and develop some kinda relations within them and make them behave as "one for all and all for one"...
    cheers.

  12. #12
    Join Date
    Jul 2002
    Posts
    788
    if i can launch the application from my process, how will that help?

    secondly, as to the information you suggested, such as window class name, ID etc, does this apply in application that developed under VB? or by other languages?

  13. #13
    Join Date
    Jul 2002
    Posts
    788
    Originally posted by siawos
    you would have to devise a combination of things to determine that, no single property/value will do the job there.
    possibilities cab be...

    • window class name (vulnerable)
    • ID(vulnerable)
    • heirarchical information of the window, like parents and their properties.
    • coordinate values (vulnerable)


    all of them are vulnerable but be a bit manager sorta person and develop some kinda relations within them and make them behave as "one for all and all for one"...
    cheers.
    May i know in what sense is window class name vulnerable? I used spy++ and note that the windows class name is not changing at all. Of course if the application developer decided to change the window control type (for example from static to edit), the window class name will get changed from static to edit other than this, i believe it will remain uchanged?

    Further to this question, if i have two same class, such as two edit controls at the same level, how do i specify which edit control i am refering? or is this the vulnerability you mentioned?

  14. #14
    Join Date
    Jul 2003
    Posts
    116
    originally posted by mce...
    if i can launch the application from my process, how will that help?
    if u can launch the target application from ur process then u can easily get the top parent handle n then enumerate them.

    originally posted by mce...

    secondly, as to the information you suggested, such as window class name, ID etc, does this apply in application that developed under VB? or by other languages?
    am sure this works for VB but others i dont know exactly, that depends on the architecture that they are built on, i remember running Spy++ on a java application and i could get certain msgs...

  15. #15
    Join Date
    Jul 2003
    Posts
    116
    originally posted by mce...


    May i know in what sense is window class name vulnerable? I used spy++ and note that the windows class name is not changing at all. Of course if the application developer decided to change the window control type (for example from static to edit), the window class name will get changed from static to edit other than this, i believe it will remain uchanged?
    check TN001 in MSDN for what i mean here, and your point is also a valid one.
    note the class name of a simple MDI or SDI generated by MFC wizard in two different instances u'll see the difference there.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured