CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: help window

  1. #1
    Join Date
    Aug 2006
    Posts
    20

    help window

    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?

  2. #2
    Join Date
    Jul 2006
    Posts
    52

    Re: help window

    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
    Last edited by giddy_guitarist; September 6th, 2006 at 01:16 PM.

  3. #3
    Join Date
    Aug 2006
    Posts
    20

    Re: help window

    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
    Last edited by xobx; September 6th, 2006 at 03:23 PM.

  4. #4
    Join Date
    Mar 2006
    Location
    Craiova, Romania
    Posts
    439

  5. #5
    Join Date
    Jul 2006
    Posts
    52

    Re: help window

    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
    Last edited by giddy_guitarist; January 5th, 2007 at 09:00 AM.

  6. #6
    Join Date
    Jun 2004
    Location
    New Jersey, USA
    Posts
    341

    Re: help window

    Here is some sample code to help you out:

    Code:
    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);
    		}
    
    	}
    "We act as though comfort and luxury were the chief requirements of
    life, when all that we need to make us happy is something to be
    enthusiastic about."

    - Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured