c# windoes api and access the TMistakeEdit object on windows app

I have been playing with help, in understanding the APIs i can use the handle to access another vs2005 form and input box, but need to access the input box on a app called coppernic, but it dosnot matter which app i am after the child object is not protected and you can see it using Windows Detective i have included two images one of the app its self and then windows detective showing the object lay out of what i am trying to place data to
any one have any idea using c# how to use the name to get access to this app using windoes api
any help would be appreciate
even an open source program that shows this data that i can pull apart would be appreciated
copper.png
copperwindef.png
sydneyguyAsked:
Who is Participating?
 
Luis PérezConnect With a Mentor Software Architect in .NetCommented:
Try this...

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetWindowText(IntPtr hwnd, String lpString);
IntPtr hwnd = FindWindow("TMistakeEdit",null);

With that you get the hWnd to the window. Not let's write in it:
SetWindowText(hwnd, "Hope that works!");

Hope that helps.
0
 
sydneyguyAuthor Commented:
well it compiled but hwnd came back as 0 so none was found
but i do get the feeling that i am really really close any ideas
have put my code as below that i am runnign in c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace coppernic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            IntPtr hwnd = Class1.FindWindow("TMistakeEdit", null);

            //  With that you get the hWnd to the window. Not let's write in it:
            Class1.SetWindowText(hwnd, "Hope that works!");




        }
    }
}

Open in new window

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace coppernic
{
    class Class1
    {
        public const int WM_SETTEXT = 0x000C;
        public const int WM_LBUTTONDOWN = 0x0201;
        public const int WM_LBUTTONUP = 0x0202;
        public const int BM_SETSTATE = 0x00F4;
        public const int BM_CLICK = 0x00F5;

        public delegate bool EnumWindowsProc(IntPtr hWnd, ref IntPtr lParam);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EnumChildWindows(HandleRef hwndParent, EnumWindowsProc lpEnumFunc, ref IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern int GetClassName(HandleRef hWnd, StringBuilder lpClassName, int nMaxCount);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(HandleRef hwnd, String lpString);

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, string lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

         [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(IntPtr hwnd, String lpString);
       

    }
}

Open in new window

0
 
sydneyguyAuthor Commented:
changing it to  IntPtr hwnd = Class1.FindWindow("TMainFrm", null); does return a hwnd of 262460
but it does not seem to find the input box TMistakeEdit

namespace coppernic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            IntPtr hwnd = Class1.FindWindow("TMainFrm", null);

            //  With that you get the hWnd to the window. Not let's write in it:
            Class1.SetWindowText(hwnd, "Hope that works!");

        }
    }
}
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
sydneyguyAuthor Commented:
think it may have something to do with
but i am just playing here so any pointers any one, thsi does not run by the way

 Class1.EnumChildWindows(hwnd, "TMistakeEdit ", ref hChld);
0
 
sydneyguyAuthor Commented:
latest code run using Child to try and return and set the value
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace coppernic
{
    public partial class Form1 : Form
    {
     //   private ProcInfo processSelectedFromList;
        private IntPtr ptrTargetEditBox;
        private IntPtr ptrTargetSearchButton;

        public Form1()
        {
            InitializeComponent();
        }


        private bool FindSearchButton(IntPtr hWnd, ref IntPtr lParam)
        {
            StringBuilder className = new StringBuilder(256);
            //    IntPtr hWnd = 854638;
            if (Class1.GetWindowText(hWnd, className, className.Capacity) > 0)
            {
                // If the target button has an accelerator (a key that can be pressed as a shortcut)
                //  then you need to include the ampersand before the letter that is the accelerator
             //   if (className.ToString().ToUpper().Contains("&SEARCH"))
             //   {
                    // If we find the text of the button, then return
                    //  this function. Return "false" to tell EnumChildWindows
                    //  we found what we are looking for
                    lParam = hWnd;

                    return false;
            //    }
            }

            // If we didn't find what we are looking for in this call,
            //  return "true" to tell EnumChildWindows we want to keep
            //  looking
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            IntPtr hwnd = Class1.FindWindow("TMainFrm", null);
        //    TContainerBar  TMistakeEdit 

            //  With that you get the hWnd to the window. Not let's write in it:
            Class1.SetWindowText(hwnd, "Hope that works!");
           
            HandleRef href = new HandleRef(null,hwnd );
            IntPtr hChld = IntPtr.Zero;

                // Continue to call EnumChildWindows until our FindSearchButton
                //  function indicates we found the control we are looking for
                while (Class1.EnumChildWindows(href, FindSearchButton, ref hChld)) ;

                        // If the hChld is IntPtr.Zero (a.k.a. null), then we didn't find
                        //  the target control
                        if (hChld != IntPtr.Zero)
                        {
                            this.ptrTargetSearchButton = hChld;

                            Class1.SetWindowText(hChld, "Hope that works!");
                   
                        }
                        else
                        {
              
                        }
                }


          //  Class1.EnumChildWindows(hwnd, "TMistakeEdit ", ref hChld);
  
    }
}

Open in new window

0
 
sydneyguyAuthor Commented:
the system is working its just going to the wrong place, after puling the dec to hax values it ending up in the tab bar control not the TMistakeEdit so workig on getting this correct now
0
 
sydneyguyAuthor Commented:
ok down the track great examples of this is in operation
http://geekswithblogs.net/Blake/archive/2009/02/03/developer-toolkit-ndash-managed-spy.aspx
managed spy gives a c# project that works and is open source and has the supplied cods

and windows Detective is a compiled application that give an insight into looking from a different direction
0
 
sydneyguyAuthor Commented:
thanks for that got that section going appreciate the help lots of code to work through but at least i am moving forward again
garry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.