summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdOfflineProvider/NativeMethods.cs
blob: ec12819237f1e308b51801e966deb8c513eea0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//-----------------------------------------------------------------------
// <copyright file="NativeMethods.cs" company="Andrew Arnott">
//     Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DotNetOpenAuth.OpenIdOfflineProvider {
	using System;
	using System.Runtime.InteropServices;
	using System.Windows;
	using System.Windows.Interop;

	internal static class NativeMethods {
		/// <summary>
		/// Gets the HWND of the current foreground window on the system.
		/// </summary>
		/// <returns>A handle to the foreground window.</returns>
		[DllImport("user32.dll")]
		internal static extern IntPtr GetForegroundWindow();
		
		[DllImport("user32.dll")]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool SetForegroundWindow(IntPtr hWnd);

		[DllImport("user32.dll")]
		private static extern IntPtr SetActiveWindow(IntPtr hWnd);

		internal static bool SetForegroundWindow(Window window) {
			return SetForegroundWindow(new WindowInteropHelper(window).Handle);
		}

		internal static void SetActiveWindow(Window window) {
			SetActiveWindow(new WindowInteropHelper(window).Handle);
		}
	}
}