Vizible’s Blog

C# – How to get foreground Window?

Posted in Programming by wearetherock on July 11, 2009
using System;
using System.Runtime.InteropServices;

namespace Foreground {
  class GetForegroundWindowTest {

    [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern IntPtr GetForegroundWindow();

    public static void Main(string[] args){
        IntPtr fg = GetForegroundWindow(); //use fg for some purpose
        Console.WriteLine(fg);
    }
  }
}
Advertisements
Tagged with: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: