Joseph Michael Pesch
VP Programming

C# Activate Window (Simulate Alt Tab Window)

by 16. June 2010 20:30

 

using System;

using System.Runtime.InteropServices;

 

namespace ActivateWindowConsoleApplication

{

  class Program

  {

    [DllImport("user32.dll")]

    public static extern Int32 SetForegroundWindow(int hWnd);

    [DllImport("user32.dll")]

    public static extern int FindWindow(string lpClassName, string lpWindowName);

 

    private static void BringToFront(string className, string CaptionName)

    {

      SetForegroundWindow(FindWindow(className, CaptionName));

    }

 

    static void Main(string[] args)

    {

        BringToFront(null, "Doc1.txt - Notepad");

        Thread.Sleep(3000);

        BringToFront(null, "Sent Items - Microsoft Outlook");

        Thread.Sleep(3000);

        BringToFront(null, "Doc3.txt - Notepad");

        Thread.Sleep(3000);

    }

  }

}

Tags:

[None]

Comments are closed