Link to home
Start Free TrialLog in
Avatar of smurff
smurff

asked on

Detecting change on another app

Hi,
How can I detect a an edit box change on another app? e.g. If calc was running and somebody put a value in, I would like my app to detect and act on it. Please help
Thanks
Avatar of inthe
inthe

i think the only way would be a keyboard hook ..but this would be in effect for all others apps unless you know the handle of the program with the edit and if it running then use loadlibrary etc...
ASKER CERTIFIED SOLUTION
Avatar of ahalya
ahalya
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
btw, as inthe noted this hook is active for all apps, and fills in your memo if Calculator is the forground window.

There are two ways to overcome this:
(1) Theoretically You can "install" the hook when Calc becomes the forgroundwindow, and then "Uninstall" it, when calc loses focus; but finding the focus change then becomes the issue (& would need another Hook i guess :-) -or a timer -

(2) Better alternative: You can find the ThreadID of the Calculator, and set the Hook with the ThreadID as the third parameter -instead of zero-); I have never done this. It shd work as per MS's docs..

As long as the Code in the DLL isn't very complex, having a system Hook shouldn't be an issue i'd think.



and btw, While we are at it, here is another proc that could be handy:
if you're interested in the contents of the edit box in the "Calc" then this code does it. (Drop in another TEdit. It'll correctly show the content in Calculator's Edit Box)


procedure TKeyHookForm.GetCalcText;

var h, c : HWND;
    p : array[0..100] of char;

begin;
h := FindWindow('SciCalc', 'Calculator');
c := GetDlgItem(h, 414);
SendMessage(c, WM_GetText, 100, longint(@p));
Edit2.Text := string(p);
end;


..and btw, it appears that i have written too much for a 50-point question :-)
Avatar of smurff

ASKER

ahalya,

Ive been working on this for far too long. Thank you for your reply, I can now get to work on this and sleep at night :)
Avatar of smurff

ASKER

It didnt run, it just terminated... Ive copied exactly what you out. Where am I going wrong?
I have checked this on my computer and it works fine. (compiled in D2).

You have to make sure that you have the "correct" classname & title for your window. Look at the constants declared in the DLL.

DO NOT assign the 'YourFormTitle' to your form in designtime, rather assign it in runtime (in the FormCreate event, Caption := YourFormTitle;)  This is to make sure that the DLL finds the correct HWND.

Give me more details of the problem; put a breakpoint in the event handler for the message to see whether you get there.  [Also you can try "F7" and step through to find where it terminates]

oops, there is one mistake in the code i copied for you.  The name of the DLL should be KBLib.dpr (and not KBHook.DPR).
Avatar of smurff

ASKER

Yes found it, that was it. Thank you once again :)

This app will be the death of me!!
can every resourse on a form be monitored for change, e.g. listbox or colour of the form....?
well, the answer is Yes, but obviously it'll get tricky, and you'll need to spend considerable effort to make them work.

if you have a specific problem, then post it.
Avatar of smurff

ASKER

Ive been playing about with this for quite some time. Theres a network monitoring program on a server and when one of the 6 servers is down then the name turns to red. I was trying to code something that would email me or notify me over udp to tell me. Now because its not my program im having to build something that will monitor the form on the display, hence thats where my question came in.
I cant seem to get the code you helped me with to work in NT, I have looked at PSAPI.DLL but its not as straight forward as the win95 code you gave me. If you can point me in the right direction or give any help that would be great. maybe girls and Delphi dont mix well :)
Well, AFAIK, my code should work on NT without any modifications.

PSAPI.DLL is needed ONLY if you want to use the ToolHelp32 functions. (and we didn't use any ToolHelp functions in the above.)

About detecting the info on the other program:
The only way i could think of is to track all the messages, the other program is getting and find out what message does it get when there is an error.  Then you can write a MessageHook (similar to our KeyboradHook), and you program will get the info whenever the error occurs.

It will be more earsier if the text in the other program changes when an error occurs. Then you can monitor the text to decide  whether there is an error.