![]() |
|
#1
|
|||
|
|||
Getting Input from a WindowI dont know if this belongs here or .net
Hey guys, I'm not sure if I named my thread right, but here goes. My goal is to create an application that will receive and analyze window xyz's output. So, have this game based on the quake 3 engine. It has a 'console', which is seperate from the main window. This console shows the output of all the events that have happened, who said what in chat, etc. What I want to do is analyze this output in my program so that I could do certain things based on the output. Say in game my name is Player, and I say !hello, the program would scan the output for !hello, and then do accordingly. I know this could be done since there are many examples (killtrackers). I had a control in VB.Net that did particularly this, however, the source wasn't included. I've asked the guy who made it and all he tells me is it was done using the .net framework. I dont know if he means the GUI part or the actual system part where it analyzes the output of the console. In my understandment, a window could be a button. Basically I'd like to know how I could see what the text in a certain button (for which I have the window handle etc.) is, so then I could later analyze this text and compare it against my variables. Perhaps a button isn't the best example, since I am mostly accessing this 'console' by it's name (maybe by using the FindWindowEx function passed with the window name). After I have this 'window', I'd like to analyze, or better yet, 'capture' this data into my program. Am I clear? Could someone please point me in the right direction? |
|
#2
|
|||
|
|||
Re: Getting Input from a WindowYes i wanna know this one too
|
|
#3
|
|||
|
|||
Re: Getting Input from a WindowWell you're on the right track with FindWindow function. Download the program AutoIt. this is a windows scripting language, but what you want is hte AutoIt Window Spy (I've also heard of a Spy++ but don't know what this is or where to get it). Anyways, the Window Spy lets you click on any window and it displays information you need for FindWindow, text and class name. Additionally, click on a control and you can get the control's text, class, etc. Once you have a handle to the control, you can call GetWindowText() and then you have a string you can search.
that was rather dense. here's some code: CPP / C++ / C Code:
P.S. Whoops, I'm so used to C++. I just realized that I wrote C code (I even remembered to use malloc instead of new) but put C++ single-line comments...oops. |
|
#4
|
|||
|
|||
Re: Getting Input from a WindowHaha, I'm a C++er but I often find myself writing C lol. Anyways, thanks for the help. Anyways, I used a program called WinSpector, I encourage you to try it out (like Spy++, free).
Anyways, in my program (I had an example to look at, although it was in VB6). Anyways, I got it working, here is an older version of my working source ( http://blank.cjb.cc/code4/?a=sb&i=22 ), but by now it already has more features. Anyways, I have encountered another 'problem'. The 'line' varaible (LPSTR) gets updated constantly. See, what I'm doing is monitoring a console 'Edit control' of a game I play. Everything that happens is logged/shown in the edit control. The last line (which is the line I get, doesn't show that in the link I gave however) is therefore constantly changing of value, to the last line logged by the console (for example, if I say 'Hi', if I die, if someone leaves, etc.). So now my problem is trying to somehow always keep an updated version. I'm stumped though, since I always think at large even when I'm not supposed to, and I dont know what to do. Someone told me to hook the edit control and wait for an EN_UPDATE message to see if the text changed, someone else said that was overkill, but do look for the EN_UPDATE message (how, using GetMessage()?). What I was thinking was either making a loop (how would I make it? what type, for or while?) or implement a timer and get the new value every certain amount of milliseconds (maybe creating this process as it's own thread). If you have any pointers on this I'd greatly appreciate. The hard thing would be testing if it worked, since you most likely dont have the game (Jedi Outcast), so pointers/hints/suggestions would be nice. The code in the link doesn't match what I have, I already implemented a 'GetLastLine' function, which I will upload later (just reformatted). EDIT: updated the code, I'll post it here as well just in case it's hard to read: Q3Tracker.cpp CPP / C++ / C Code:
Tracker.h CPP / C++ / C Code:
Tracker.cpp CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: Getting Input from a Windowi believe you may actually have to use a hook. Here is why. first a little background: You obviously know about the concept of a window procedure; your main window has one. the window containing the edit control you're tracking has a window procedure, too. that window procedure receives EN_CHANGE and EN_UPDATE messages. you want those messages. the obvious choice would be subclassing, the idea of which is substituting your own function for another window's window procedure, in which you snoop in thte messages you're interested in and then call the original window procedure. this would work for you (i think) if you have a version of Windows before NT/2000/XP. However, NT/2k/XP have decided that you can't subclass windows that aren't in your process. how inconvenient. that's why you would have to use a message hook.
A hook is a function that you register with Windows, that receives notification when certain things occur. there are many kinds of hooks -- some listen to window creation and destruction, some to mouse clicks, some to messages. the last one is what you want. there are two kinds of hooks -- system hooks and thread-specific hooks. you really only care about the messages in one specific thread (the thread containing the console), so you don't need to bog down the whole system by checking every message. because the thread you want to hook is in another process (here comes those annoying security features again) you'll need to put your hook handler in a DLL. you register the hook by calling SetWindowsHookEx(). In this case, we'll want a WH_GETMESSAGE hook, so we can sniff out EN_UPDATE. you'll need to give it an HMODULE returned from LoadLibrary() of your DLL as the hMod parameter, and for the lpfn parameter, the pointer to your hook function received by GetProcAddress(). Now, you ask, all i have is the HWND, but i want the thread ID? good question. for this there is the GetWindowThreadProcessId() function. you would call it with the window containing the console, not the edit control itself, although it probably wouldn't matter. Then, you would check WM_COMMAND messages in your hook handler, and when you got an EN_UPDATE notification, check if it's the HWND of the edit control you are tracking, and if it is, call your GetLastLine function. look up all these functions on MSDN for more reference. if i went over something too fast, don't hesitate to ask me to elaborate. i can also help in creating the DLL, as i have done this before and started out as clueless about it as you may be. hth, ubergeek |
|
#6
|
|||
|
|||
Re: Getting Input from a WindowI greatly appreciate all your help, ubergeek. I at first didn't want to use hooks because as much as I tried, I didn't know where to start (what functions to use, etc.). This is very informative, and I wouldn't like to bother you anymore, so I'll look them up on my own. However, if possible, could you please provied a 'pseudo-code like' snippet? Just showing the order in which these functions are called, so I can know what to look up and what to pass to what (although you explained that very well). Also, do you mean I have to create a dll? or inject my hook into one? Thanks a lot for the information, greatly appreciated.
|
|
#7
|
|||
|
|||
Re: Getting Input from a WindowhookSetter.cpp (in a .exe file):
Code:
Code:
i hope that explanation was almost follow-able, tell me what you're still confused about |
|
#8
|
|||
|
|||
Re: Getting Input from a WindowThanks man, anyways, for the
Code:
IS it like a simple message looop? So I'd do Code:
I dont need the stuff exactly just bit more uh, hintier, thanks for the help so far ubergeek! |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to minimize a application to the system tray? | Thomas555 | C++ Forum | 12 | 20-May-2005 14:35 |
| #including resource file causing window procedure to be undeclared??? | ubergeek | C++ Forum | 3 | 07-Feb-2005 15:39 |
| Changing window start colour | Rosdahale | C++ Forum | 5 | 19-Jan-2005 16:51 |
| [C] Discarding input | Alhazred | C Programming Language | 8 | 04-Aug-2004 12:45 |
| IP tables | rogermark100 | C Programming Language | 6 | 18-Apr-2004 08:22 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The