diff options
| author | Dave Wilson <[email protected]> | 2015-03-17 19:50:07 -0700 |
|---|---|---|
| committer | Dave Wilson <[email protected]> | 2015-03-17 19:50:07 -0700 |
| commit | 97cf5197cf5b882b2c689d8dc2b555f2edf8f418 (patch) | |
| tree | 46f3701832d70b420eb0fc0eb93261f9da45db3f /print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/WindowHelper.cs | |
| parent | ef1905bf1e8825bb31120dfb27e0daf3154d859a (diff) | |
Initial publish
Diffstat (limited to 'print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/WindowHelper.cs')
| -rw-r--r-- | print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/WindowHelper.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/WindowHelper.cs b/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/WindowHelper.cs new file mode 100644 index 00000000..fe830921 --- /dev/null +++ b/print/v4PrintDriverSamples/PrinterExtensionSample/ExtensionSample/WindowHelper.cs @@ -0,0 +1,83 @@ +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved +// +// +// Abstract: +// +// This file contains helper methods that provide a friendly way to access win32 window functions. + +using System; +using System.Runtime.InteropServices; + +namespace Microsoft.Samples.Printing.PrinterExtension.Helpers +{ + class WindowHelper + { + /// <summary> + /// P/Invoke signature for Win32 function "SetForegroundWindow". + /// </summary> + /// <param name="hwnd">Handle to window</param> + [return: MarshalAs(UnmanagedType.Bool)] + [DllImport("User32", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] + public static extern bool SetForegroundWindow(IntPtr hwnd); + + /// <summary> + /// Wrapper for Win32 function "FlashWindowEx" + /// </summary> + /// <param name="hWnd">Handle of the window to flash</param> + public static bool FlashWindow(IntPtr hWnd) + { + FLASHWINFO fInfo = new FLASHWINFO(); + + fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); + fInfo.hwnd = hWnd; // Handle to window + fInfo.uCount = UInt32.MaxValue; // Number of times to flash + fInfo.dwTimeout = 0; // Use default cursor blink rate + // Flash both window caption and taskbar button, until the window is brought to the foreground. + fInfo.dwFlags = (uint)(FLASHW.ALL | FLASHW.TIMERNOFG); + + return FlashWindowEx(ref fInfo); + } + + #region private members + + /// <summary> + /// P/Invoke signature for Win32 function "FlashWindowEx". + /// </summary> + [return: MarshalAs(UnmanagedType.Bool)] + [DllImport("User32", CharSet = CharSet.Auto, SetLastError = false, ExactSpelling = true)] + private static extern bool FlashWindowEx(ref FLASHWINFO pwfi); + + [StructLayout(LayoutKind.Sequential)] + private struct FLASHWINFO + { + public UInt32 cbSize; + public IntPtr hwnd; + public UInt32 dwFlags; + public UInt32 uCount; + public UInt32 dwTimeout; + } + + /// <summary> + /// Represents the FLASH_Xxx flags + /// </summary> + [Flags] + private enum FLASHW : uint + { + /// <summary> + /// Flash both the window caption and taskbar button + /// </summary> + ALL = 3, + /// <summary> + /// Flash continuously until the window comes to the foreground. + /// </summary> + TIMERNOFG = 12 + } + + #endregion + } +} |
