xobx
September 5th, 2006, 04:43 PM
i downloaded a programe called windowfinder
that can get info about windows i think!?, like this:
X Pos 330
Y Pos 375
Window Handle == 0x000D04AE
Class Name : SysTabControl32.
RECT.left == 151.
RECT.top == 237.
RECT.right == 511.
RECT.bottom == 557.
can i in some how use this to like push a button in that window i got this from?
giddy_guitarist
September 6th, 2006, 12:47 PM
hie there ,
ok i don think your subject is appropriate! .. something like "push button in another wnd" would be good!
anyway ... i'm not too much of an acomplished C# programmer.. but i did something like this in VB ..
knowing a little VC would really help you to understand this , and you need to use API (unmanaged) .When a butotn is clicked , windows sends a message to the programs wndProc , so that it can handle it..... .what you have to do is send this MESSAGE yourself as if the button was clicked...
although u COULD use the window handle you already have.. you SHOULD do the foll :
long appsHwnd = FindWindow( <classname> , <caption on the app>);
if there are no other apps with the same classname then you can have the second param null.
now use SendMessage API to send a clicked message to the wndProc , this would be a WM_COMMAND message , telling the app that somethhing was clicked.
SendMessage(appsHwnd , WM_COMMAND , <button id>, NULL);
<button id> is an ID used to identify the button in a VC program .. u need an application called Exescope to find out what he ID for the button is...
Hope i Helped!! =)!
Gideon
xobx
September 6th, 2006, 03:15 PM
ok i didnt get so much off it, but i downloaded Exescope and where do i get the id of the button from it
and what is API?
can you post you VB code here also
creatorul
September 6th, 2006, 03:40 PM
http://en.wikipedia.org/wiki/Application_programming_interface
giddy_guitarist
September 7th, 2006, 01:23 AM
Hie,
....u should know what API is if your doing windows programmer.. .. .look at THIS article
http://en.wikipedia.org/wiki/Windows_API
this is the API we're talking about....basically they're a HUGE (about 2000 -3000) set of NON-OBJECT ORIENTED functions that primarily come from user32.dll , gdi32.dll , kernal32.dll ...... and they enable u to do almost everything u want to in windows... the bad part is they're not so easy to use .. and they're unmanaged which can lead to a number of problems .. .so Microsoft designed .NET now.Most of the classes are a rewritten .. a FEW classes still sit on the API .... but then SOMETIMES u need to call the API to do your dirty work .. This is called p/Invoke (platform invoke)
READ THIS ARTICLE ->
http://www.codeproject.com/csharp/c__and_api.asp
AFTER THAT u can go here. .. http://eric.aling.tripod.com/PB/netapi.htm to get any API declaration u want.
as for exescope ... open the Resource node , then the dialog node.. .under it there will be all the dialogs used.. .select the right one... on the right pane you'll see DefPushButton...slect it... and on the top you'll see the ID.
Hope i helped
Gideon
stardv
September 7th, 2006, 09:24 AM
Here is some sample code to help you out:
public class Controller
{
public IntPtr ptrToWindow = IntPtr.Zero;
[DllImport("user32.dll",CharSet=CharSet.Auto)]
static extern IntPtr FindWindow(string lpClassName,string lpszWindow);
[DllImport("user32.dll",CharSet=CharSet.Auto)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint="SendMessage")]
static extern bool SendMessage(IntPtr hWind,uint Msg,int wParam, int lParam);
[DllImport("user32.dll")]
static extern int PostMessage(IntPtr hWnd, uint Msg, int wParam,int iParam);
[DllImport("user32.dll")]
static extern IntPtr GetMenue(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr GetSubMenue(IntPtr hMenue, int nPos);
[DllImport("user32.dll")]
static extern IntPtr GetMenueItemID(IntPtr hMenue);
public Controller(IntPtr hWind)
{
this.ptrToWindow = hWind;
}
public Controller(string lpClassName, string lpWindowName)
{
this.ptrToWindow = FindWindow(lpClassName,lpWindowName);
}
public Controller(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow)
{
this.ptrToWindow = FindWindowEx(hwndParent,hwndChildAfter,lpszClass,lpszWindow);
}
public Controller(IntPtr hwndParent, int Index)
{
int ct=0;
IntPtr result = IntPtr.Zero;
do
{
result = FindWindowEx(hwndParent,result,null,null);
if(result != IntPtr.Zero) ++ct;
}while(ct< Index && result !=IntPtr.Zero);
this.ptrToWindow = result;
}
public bool IsValid
{get {return this.ptrToWindow != IntPtr.Zero;}}
public void SendChar(char c)
{
uint WM_CHAR = 0x0102;
SendMessage(this.ptrToWindow, WM_CHAR,c,0);
}
public void SendChars(string s)
{
foreach(char c in s) SendChar(c);
}
public void ClickOn()
{
uint WM_LBUTTONDOWN = 0x0201;
uint WM_LBUTTONUP= 0x0202;
PostMessage(this.ptrToWindow, WM_LBUTTONDOWN,0,0);
PostMessage(this.ptrToWindow, WM_LBUTTONUP,0,0);
}
}