Click External Button on seperate windows app

Posted on 2011-04-22
Last Modified: 2012-05-11
I would like to Programatically click on an external Button in a windows app.
I have downloaded Windowscrape.dll and using SPY++ to get the handler, etc...
using Visual Studio 2010.
Most examples i've seen haven't been helping me out...would appreciate it!
Question by:Shaggy1
    LVL 14

    Expert Comment

    a vb code, but you can get ideas through the lines of code you will see;

    Accepted Solution

    Figured it is what i got..

     [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
            static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
            static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
            public enum MouseEventFlags
                LEFTDOWN = 0x00000002,
                LEFTUP = 0x00000004,
                MIDDLEDOWN = 0x00000020,
                MIDDLEUP = 0x00000040,
                MOVE = 0x00000001,
                ABSOLUTE = 0x00008000,
                RIGHTDOWN = 0x00000008,
                RIGHTUP = 0x00000010
            public static void LeftClick(int x, int y)
                Cursor.Position = new System.Drawing.Point(x, y);
                mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
                mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
            private void timer2_Tick(object sender, EventArgs e)
                LeftClick(1050, 72);
                LeftClick(1180, 77);
                LeftClick(1180, 100);

    Open in new window


    Author Closing Comment

    this is the solution

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now