Title: Textify me, captain
JoeImp - April 27, 2005 01:50 AM (GMT)
Ok, this is what I need to do:
Let's say I know I'm going to recieve an instant message on AIM from a specific person. Because I know who it is from, I know the title of the window, so I can get a handle to it using FindWindow(). What I need though, is some way to get the text that was sent to me in that instant message. GetWindowText() doesnt seem like it will work, IndirectGetWindowText() is Win 2000 specific, I don't really know what to do.
Any thoughts? Is it possible? You can just throw a function name at me if you are lazy, I'll figure out what I need, just need to get started.
Imp
donprogc++ - April 27, 2005 02:30 AM (GMT)
some functions
| CODE |
| GetWindowText(); // dont know why it shouldnt work |
you can try
or
| CODE |
HWND hwnd; // findwindow(); SendMessage(hwnd, WM_GETTEXT , 0, 0); // I dont know what you would set the params though |
donprogc++ - April 27, 2005 02:33 AM (GMT)
i looked up some other function
| CODE |
int InternalGetWindowText( HWND hWnd, LPWSTR lpString, int nMaxCount );
|
and i looked up the sendmessage params
http://msdn.microsoft.com/library/default..../wm_gettext.aspthat link should help :)
JoeImp - April 27, 2005 02:42 AM (GMT)
GetWindowText() will not work because it says it won't get text of controls owned by other windows or something, I don't know. All it seems to do is return the title of the window.
InternalGetWindowText() will not work because as my post said, it only compiles under Win2K or something, it won't compile at all for me.
I'll check out GetDlgItemText()
[EDIT]
For GetDlgItemText() -
Parameters
hDlg
[in] Handle to the dialog box that contains the control.
nIDDlgItem
[in] Specifies the identifier of the control whose title or text is to be retrieved.
How am I supposed to get nIDDlgItem?
Thanks for the replies!
donprogc++ - April 27, 2005 03:09 AM (GMT)
use this
| CODE |
HWND hwnd; // use findwindow GetDlgItem(hwnd); // pass this as a parameter |
or if that doesnt work try the SendMessage with WM_GETTEXT
JoeImp - April 27, 2005 03:26 AM (GMT)
Something like this doesn't work:
| CODE |
#include <windows.h> #include <iostream>
using namespace std;
void main() { HWND hwnd; HWND control; char buffer[1024]; hwnd = FindWindow(NULL, "PROGRAM NAME"); control = GetDlgItem(hwnd, NULL); GetWindowText(control, (char *)buffer, 1024); }
|
Mostly because I don't know what to pass as the second parameter to GetDlgItem.
[EDIT] - What the heck do I put for that second parameter, I can't go on without it
NOFX - April 27, 2005 10:08 AM (GMT)
| QUOTE (JoeImp @ Apr 27 2005, 03:26 AM) |
Something like this doesn't work:
| CODE | #include <windows.h> #include <iostream>
using namespace std;
void main() { HWND hwnd; HWND control; char buffer[1024]; hwnd = FindWindow(NULL, "PROGRAM NAME"); control = GetDlgItem(hwnd, NULL); GetWindowText(control, (char *)buffer, 1024); }
|
Mostly because I don't know what to pass as the second parameter to GetDlgItem.
[EDIT] - What the heck do I put for that second parameter, I can't go on without it
|
If you mean the second parameter for GetDlgItem, that is the name of the control. Like if you create a button you define it as
#define IDB_BUTTON
So IDB_BUTTON is the 2nd parameter.
JoeImp - April 27, 2005 11:00 AM (GMT)
Yeah, but how can I know what the text box is called if it is not my program, and I don't have the source to it? I can't get a handle to the text box if I don't have the name of it, therefore I can't get the text from it.
NOFX - April 27, 2005 12:55 PM (GMT)
| QUOTE (JoeImp @ Apr 27 2005, 11:00 AM) |
| Yeah, but how can I know what the text box is called if it is not my program, and I don't have the source to it? I can't get a handle to the text box if I don't have the name of it, therefore I can't get the text from it. |
Spy++ gives the handle i think in numbers. Not sure though if that will work but you can try it.
JoeImp - April 27, 2005 10:53 PM (GMT)
I Spy++ the text box and get this:
Handle: 001B052E
Caption: ""
Class: Ate32Class
I close the IM I sent to myself, and send myself another, and do the same thing:
Handle: 001A05EC
Caption: ""
Class: Ate32Class
The handle obviously changes with every new IM that is sent. I hope I can use the class name "Ate32Class" somehow. I'll scour through msdn for a function that'll work. If anybody wants to throw together a 2-3 line example for me, that would help a lot, or any more help at all would be appreciated ^__^
[EDIT] - Seems like I can use FindWindow() for the textbox directly, then GetDlgItemText(). I'll see if I can throw something together that'll work.
[EDIT 2] - Nope, FindWindow will not return a handle to the textbox given the class name. Arg.
Basically, it comes down to: How do I get a handle to a textbox control in another application.
JoeImp - April 27, 2005 11:52 PM (GMT)
30 min later:
PROBLEM SOLVED.
Here's the code I used:
| CODE |
#include <windows.h> #include <iostream>
using namespace std;
void main() { char buffer[1024]; memset(buffer, 0, 1024); HWND Window; HWND Edit = NULL;
Window = FindWindow(NULL, "JoeImpellizzieri : JoeImpellizzieri - Instant Message");
if (Window == NULL) { cout << "Unable to find parent window"; }
while ((Edit = FindWindowEx(Window, Edit, NULL, NULL)) != 0) { SendMessage(Edit, WM_GETTEXT, 1024, (LPARAM) buffer); cout << '\n' << buffer; } }
|
I sent myself the message 'Testing .. 1 .. 2 .. 3', you can see it in the results below, in the big chuck of html there. Basically, it spits out every child window it can find. I'll just have to refine it, should be easy.
RESULTS:
| CODE |
From: JoeImpellizzieri To: JoeImpellizzieri
<HTML><BODY BGCOLOR="#010101"><B><FONT COLOR="#0000ff" LANG="0">JoeImpellizzieri <!-- (7:49:16 PM)--></B></FONT><FONT COLOR="#0000ff" BACK="#010101">:</FONT><FON T COLOR="#000000"> </FONT><FONT COLOR="#fefefe" FACE="Arial" SIZE=1>Testing 1 .. <BODY BGCOLOR="#010101"><B><FONT COLOR="#ff0000" FACE="Times New Roman" SIZE=3>J oeImpellizzieri<!-- (7:49:16 PM)--></B>:</FONT><FONT COLOR="#000000"> </FONT><FO NT COLOR="#fefefe" FACE="Arial" SIZE=1>Testing 1 .. 2 .. 3</FONT></BODY></HTML>
&Send
<HTML><BODY BGCOLOR="#ffffff"><FONT LANG="0">This member is using a</FONT></BODY ></HTML> <HTML><BODY BGCOLOR="#ffffff"><FONT LANG="0"><A HREF="http://aimtoday.aol.com/to day/mobile/presence.adp" TARGET="_aim_today"></FONT><FONT BACK="#ffffff">mobile device.</FONT></BODY></HTML>
<HTML><BODY BGCOLOR="#ffffff"><FONT LANG="0">This member is using a</FONT></BODY ></HTML> <HTML><BODY BGCOLOR="#ffffff"><FONT LANG="0"><A HREF="http://aimtoday.aol.com/to day/mobile/presence.adp" TARGET="_aim_today"></FONT><FONT BACK="#ffffff">mobile device.</FONT></BODY></HTML>
&Warn Bloc&k
Send &Instant Message...
Your buddy is connected Get AIM E&xpressions Play Games Start Live Video &Talk
&Chat
Close AIM Theme Panel Press any key to continue
|
THANK YOU FOR ALL HELP!