Getting text from another window (C/C++/VC++)

This is a discussion on Getting text from another window (C/C++/VC++) within the Windows Programming forums, part of the Platform Specific Boards category; I would like to be able to capture text from an edit box that is in a seperate window from ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Getting text from another window (C/C++/VC++)

    I would like to be able to capture text from an edit box that is in a seperate window from the program that captures it. Then that text could be a char* or a Cstring, and I could do whatever with it. For example, say I have some other program running whos window has the following qualities:

    >>>>>>>>>>>> Window Details <<<<<<<<<<<<<
    Title: Test Window
    Class: Afx:400000:28:14a6:0:521f
    Size: X: 0 Y: 0 W: 800 H: 573

    >>>>>>>>>>> Mouse Details <<<<<<<<<<<
    Window: X: 184 Y: 511
    Cursor ID: 2

    >>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<
    RGB: Hex: 0xFFF6CF Dec: 16774863

    >>>>>>>>>>> Control Under Mouse <<<<<<<<<<<
    Size: X: 9 Y: 457 W: 385 H: 85
    Control ID: 1003
    ClassNameNN: Edit5
    Text:
    (Control is hidden)

    Then I would run my program, and it would keep looking at Edit5 for certain text, say "AB1" and "AB2". When found, the text containing "AB1" or "AB2" would be placed in a variable in my program.

    How would I do this?

    (Running Visual C++ 6.0 and Borland C++ 5.x)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    I wonder why the only reason I can come up with for wanting to do this, is to write a password snatcher.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    ahhhaah

    Perhaps you think too negitivly, or you dont think far enough ahead?

    To do what you have suggested, you must have the program installed ON the persons computer that you would grab a password from. Then, it would only work with the windows it was pre-programed for. Why not just a freaking keylogger, and grab ALL the passwords? DUH?

    No, this is a program I am making in conjunction to another. It extracts my hand histories for my hold'em games (Play money, I dont gamble real money), then creates a file with statistics on what cards I had when I won, and what cards I had when I lost.

    That file will be used in conjunction with the new program (the one I wanted help with). In that edit box, when I am delt my hole cards, it would say my hole cards "Ah Kc" (ace hearts, king clubs). My program would see that, then look up ace king for hole cards, and show me the games I have won and lost with those cards, and in what situations. I could then write notes in my program, and save it to a file.

    Normally the poker program saves all info in my hand history files, but only after the game is finished. Entering "AK" into a box every time i was dealt a hand would be tedious, hence the need to get the info as its being presented, automatically.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I think you can just use FindWindowEx() to get a handle to the window you want to receive the text from. Then send the WM_GETTEXT message to receive the text.

    This wont allow you to know when an edit box changes though. In order to do that, you need to subclass the window with SetWindowLongPtr() and catch the EN_CHANGE message. The problem is that you can't subclass a window from another process and change its procedure function.

    You can try calling SetWindowsHookEx() on the thread that runs your poker game. This will allow you to catch the messages from the windows procedure.

    The best way to solve your problem though is probably to sniff packets. Use the Winpcap library, and decode all the packets that are sent from the server you are playing poker on. This will allow you to see every card that is delt to you, and then you can perform whatever analysis you need.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    ok

    Sniffing the packets wont work, since the traffic comming from the server is highly encrypted. Remember this poker site plays real $ too, and they cannot have people knowing every little detail that is NOT displayed normally (I.E. in the windows you see).

    I will look up the SetWindowsHookEx() function and see how it works.
    I am kind of new to windows programming, usually just do console stuff. So if you are free to explain an outline of what I would need to do, or give any info on how I would use the function, let me know. Otherwise if I have questions after looking this function up, I will post them.

    Thanks again.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Sniffing the packets wont work, since the traffic comming from the server is highly encrypted. Remember this poker site plays real $ too, and they cannot have people knowing every little detail that is NOT displayed normally (I.E. in the windows you see).
    I bet you find that it is a lot easier than you think. The poker server is not going to send you the cards that everyone else has, just your own. There is no need to encrypt the data that is being sent, it is probably just in some binary form.

    If you are new to windows programming, then you will probably run into several problems when attempting a project like this. What you are trying to do is pretty advanced. I can't really give you step by step instructions without knowing the details of the poker program you are using and such. When you run into specific problems, post them here and I (or someone else) will help you through it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21