1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.View
7 using System.Runtime.InteropServices;
9 using System.Windows.Interop;
10 using Microsoft.Tools.Common;
12 static class WindowExtensionMethods
14 public static void ShowContextHelpButton(this Window window)
16 IntPtr hwnd = new WindowInteropHelper(window).Handle;
17 IntPtr exStyle = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_EXSTYLE);
20 exStyle = new IntPtr(exStyle.ToInt32() | Win32Interop.WS_EX_CONTEXTHELP);
24 exStyle = new IntPtr(exStyle.ToInt64() | ((long)Win32Interop.WS_EX_CONTEXTHELP));
26 Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_EXSTYLE, exStyle);
29 public static void HideMinMaxButton(this Window window)
31 IntPtr hwnd = new WindowInteropHelper(window).Handle;
32 IntPtr style = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_STYLE);
35 int intValue = style.ToInt32();
36 intValue = SetBit(Win32Interop.WS_MAXIMIZEBOX, intValue, false);
37 intValue = SetBit(Win32Interop.WS_MINIMIZEBOX, intValue, false);
38 style = new IntPtr(intValue);
42 long longValue = style.ToInt64();
43 longValue = SetBit((long)Win32Interop.WS_MAXIMIZEBOX, longValue, false);
44 longValue = SetBit((long)Win32Interop.WS_MINIMIZEBOX, longValue, false);
45 style = new IntPtr(longValue);
47 Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_STYLE, style);
50 public static void AddWindowsHook(this Window window, HwndSourceHook wmHandler)
52 IntPtr hwnd = new WindowInteropHelper(window).Handle;
53 HwndSource source = HwndSource.FromHwnd(hwnd);
54 source.AddHook(wmHandler);
57 public static void RemoveWindowsHook(this Window window, HwndSourceHook wmHandler)
59 IntPtr hwnd = new WindowInteropHelper(window).Handle;
60 HwndSource source = HwndSource.FromHwnd(hwnd);
61 source.RemoveHook(wmHandler);
64 public static void HideIcon(this Window window)
66 IntPtr hwnd = new WindowInteropHelper(window).Handle;
67 IntPtr exStyle = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_EXSTYLE);
70 exStyle = new IntPtr(exStyle.ToInt32() | Win32Interop.WS_EX_DLGMODALFRAME);
74 exStyle = new IntPtr(exStyle.ToInt64() | ((long)Win32Interop.WS_EX_DLGMODALFRAME));
76 Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_EXSTYLE, exStyle);
78 Win32Interop.SendMessage(hwnd, Win32Interop.WM_SETICON, new IntPtr(Win32Interop.ICON_SMALL), IntPtr.Zero);
79 Win32Interop.SendMessage(hwnd, Win32Interop.WM_SETICON, new IntPtr(Win32Interop.ICON_BIG), IntPtr.Zero);
82 private static long SetBit(long mask, long value, bool flag)
94 private static int SetBit(int mask, int value, bool flag)
102 return value & ~mask;