How to launch application and Press on the button on that window

  1. Launch the App
  2. Loop through Process
  3. Get the process Name Based on our Application Name. Basically this get's the process on your desktop/start bar
  4. If found the same, Get the Window Handle, process.MainWindowHandle
  5. After having the Handle, use the WinAPI 
    • [DllImport("user32.dll")]
    • [return: MarshalAs(UnmanagedType.Bool)]
    • internal static extern bool GetWindowRect(IntPtr hwnd, out Diversity.Web.Test.WebUIUnitTest.Rect lpRect);
    • Create a Struct To hold it.
    • [StructLayout(LayoutKind.Sequential)]
              public struct Rect
              {
                  public int Left{get;set;}
                  public int Top{get;set;}
                  public int Right { get; set; }
                  public int Bottom { get; set; }
                  public override bool Equals(object obj)
                  {
                      return base.Equals(obj);
                  }
                  public override int GetHashCode()
                  {
                      return base.GetHashCode();
                  }
                  public static bool operator ==(Rect first, Rect second)
                  {
                      return ((first.Left == second.Left) && (first.Right == second.Right) && (first.Top == second.Top) && (first.Bottom == second.Bottom));
                  }
                  public static bool operator !=(Rect first, Rect second)
                  {
                      return !(first == second);
                  }
              }
  6. Use the Function and Passed in the Handle, NativeMethods.GetWindowRect(hWnd, out rct);
  7. Use the Library i found earlier, which has mouse simulator, click the x and y that you want to, but please measure the distance first
You might also want to Maximize the Window first and click using the settoforeground API
Share this post: | | | |
Published Friday, February 20, 2009 10:19 AM by cipto
Filed under:

Comments

# re: How to launch application and Press on the button on that window

Monday, February 23, 2009 2:53 PM by ariswb

bisa minta tlng detail contohnya gak?

thx

# re: How to launch application and Press on the button on that window

Monday, February 23, 2009 3:12 PM by cipto

Scenario:

Ex: Launch Browser .

Click on Reload Button,

Or send keys of Reload.