I've done this a couple years ago, but I certainly dont remember what API's I used. Anyone know off had on how to do it?
Printable View
I've done this a couple years ago, but I certainly dont remember what API's I used. Anyone know off had on how to do it?
FindWindow and FindWindowEx APIs should help you here :)
I think FindWindowEx will do it, any ideas on the parameters? Here's what I got so far:
FindWindowEx(GetForegroundWindow(), null, null, nulll);
and its not much. if spy++ can do it so can I, I'm pretty darn sure I've done this before, in fact I know I have because I wrote a macro program that would record keyboard and mouse events, and play them back. I would have had to of got the control hwnd to have used sendmessage correctly..... Problem is it was in vb6, and on another harddrive that I have stored away right now.... gurrrrr.....
Well, now I'm thinking maybe I created a global mouse and keyboard hook, and just threw in the recorded key and mouse events into the message queue ... I dunno, Hopefully someone will shed some light, in the meantime, when I get a day off from work, I'll dig up my harddrive, and try to find my original code.
You'll need both FindWindow and FindWindowEx.
FindWindow finds the external application's main window, and FindwindowEx finds a window ( a control ) inside the external application's main window.
Here's a couple examples on FindWindow :
http://www.devasp.net/net/articles/display/690.html
http://www.dotnetspider.com/resource...indow-API.aspx
Here's a VB.NET example of FindWindowEx :
http://www.codeguru.com/forum/showthread.php?t=444234
Should be quite simple to convert to C# if you know a bit of VB. Just in case, here's a nice VB.NET to C# converter :
http://www.developerfusion.com/tools.../csharp-to-vb/
Hey, thanks I'll definately check out those links. Funny you mention vb, because I am writing this in vb. :)
Remember I'm trying to get the hwnd for any control on any application, I'm not going to know their names.
You may also need to use a program called Spy++ ( It should be on your system, listed under Visual Studio .NET Tools ). This program will show all the current Windows and Child Windows for any open application; so it should be relatively easy to obtain the name of the particular control(s) in question. :)
If you're writing this app in VB, you must please ask in the appropriate VB forum
Thanks, but I dont need to ask in vb forum, as vb=c#, and any source code I provide you will be in c#. As far as using SPy++ thats impossible, I dont know what windows the enduser will be sending messages to. Like I indicated in my previous post, I need to get the handle at runtime for controls in any application in any window.
C# solutions are fine and expected since I'm in a c# forum.
Thanks.