// Stephen Toub
// stoub@microsoft.com
//
// ActiveWindow.cs v1.0.0
// 8/28/02
//
// Implements IWin32Window where Handle returns the handle of the system's foreground window.
// Can be used with MessageBox to display the box in front of the active window, such as:
// MessageBox.Show(ActiveWindow.Active, "Hello, World!");
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Toub.Windows.Forms
{
///
public class ActiveWindow : IWin32Window
{
#region Private Members
///
private static ActiveWindow _window = new ActiveWindow();
#endregion
#region Construction
///
private ActiveWindow() {}
#endregion
#region Public Properties
///
public static IWin32Window Active { get { return _window; } }
#endregion
#region Private Functions
///
[DllImport("user32.dll")]
private static extern int GetForegroundWindow();
///
System.IntPtr IWin32Window.Handle
{
get { return new System.IntPtr(GetForegroundWindow()); }
}
#endregion
}
}
No comments:
Post a Comment