Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / WindowExtensionMethods.cs / 1305376 / WindowExtensionMethods.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; static class WindowExtensionMethods { public static void ShowContextHelpButton(this Window window) { IntPtr hwnd = new WindowInteropHelper(window).Handle; IntPtr exStyle = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_EXSTYLE); if (IntPtr.Size == 4) { exStyle = new IntPtr(exStyle.ToInt32() | Win32Interop.WS_EX_CONTEXTHELP); } else { exStyle = new IntPtr(exStyle.ToInt64() | ((long)Win32Interop.WS_EX_CONTEXTHELP)); } Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_EXSTYLE, exStyle); } public static void HideMinMaxButton(this Window window) { IntPtr hwnd = new WindowInteropHelper(window).Handle; IntPtr style = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_STYLE); if (IntPtr.Size == 4) { int intValue = style.ToInt32(); intValue = SetBit(Win32Interop.WS_MAXIMIZEBOX, intValue, false); intValue = SetBit(Win32Interop.WS_MINIMIZEBOX, intValue, false); style = new IntPtr(intValue); } else { long longValue = style.ToInt64(); longValue = SetBit((long)Win32Interop.WS_MAXIMIZEBOX, longValue, false); longValue = SetBit((long)Win32Interop.WS_MINIMIZEBOX, longValue, false); style = new IntPtr(longValue); } Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_STYLE, style); } public static void AddWindowsHook(this Window window, HwndSourceHook wmHandler) { IntPtr hwnd = new WindowInteropHelper(window).Handle; HwndSource source = HwndSource.FromHwnd(hwnd); source.AddHook(wmHandler); } public static void RemoveWindowsHook(this Window window, HwndSourceHook wmHandler) { IntPtr hwnd = new WindowInteropHelper(window).Handle; HwndSource source = HwndSource.FromHwnd(hwnd); source.RemoveHook(wmHandler); } public static void HideIcon(this Window window) { IntPtr hwnd = new WindowInteropHelper(window).Handle; IntPtr exStyle = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_EXSTYLE); if (IntPtr.Size == 4) { exStyle = new IntPtr(exStyle.ToInt32() | Win32Interop.WS_EX_DLGMODALFRAME); } else { exStyle = new IntPtr(exStyle.ToInt64() | ((long)Win32Interop.WS_EX_DLGMODALFRAME)); } Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_EXSTYLE, exStyle); Win32Interop.SendMessage(hwnd, Win32Interop.WM_SETICON, new IntPtr(Win32Interop.ICON_SMALL), IntPtr.Zero); Win32Interop.SendMessage(hwnd, Win32Interop.WM_SETICON, new IntPtr(Win32Interop.ICON_BIG), IntPtr.Zero); } private static long SetBit(long mask, long value, bool flag) { if (flag) { return value | mask; } else { return value & ~mask; } } private static int SetBit(int mask, int value, bool flag) { if (flag) { return value | mask; } else { return value & ~mask; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; static class WindowExtensionMethods { public static void ShowContextHelpButton(this Window window) { IntPtr hwnd = new WindowInteropHelper(window).Handle; IntPtr exStyle = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_EXSTYLE); if (IntPtr.Size == 4) { exStyle = new IntPtr(exStyle.ToInt32() | Win32Interop.WS_EX_CONTEXTHELP); } else { exStyle = new IntPtr(exStyle.ToInt64() | ((long)Win32Interop.WS_EX_CONTEXTHELP)); } Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_EXSTYLE, exStyle); } public static void HideMinMaxButton(this Window window) { IntPtr hwnd = new WindowInteropHelper(window).Handle; IntPtr style = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_STYLE); if (IntPtr.Size == 4) { int intValue = style.ToInt32(); intValue = SetBit(Win32Interop.WS_MAXIMIZEBOX, intValue, false); intValue = SetBit(Win32Interop.WS_MINIMIZEBOX, intValue, false); style = new IntPtr(intValue); } else { long longValue = style.ToInt64(); longValue = SetBit((long)Win32Interop.WS_MAXIMIZEBOX, longValue, false); longValue = SetBit((long)Win32Interop.WS_MINIMIZEBOX, longValue, false); style = new IntPtr(longValue); } Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_STYLE, style); } public static void AddWindowsHook(this Window window, HwndSourceHook wmHandler) { IntPtr hwnd = new WindowInteropHelper(window).Handle; HwndSource source = HwndSource.FromHwnd(hwnd); source.AddHook(wmHandler); } public static void RemoveWindowsHook(this Window window, HwndSourceHook wmHandler) { IntPtr hwnd = new WindowInteropHelper(window).Handle; HwndSource source = HwndSource.FromHwnd(hwnd); source.RemoveHook(wmHandler); } public static void HideIcon(this Window window) { IntPtr hwnd = new WindowInteropHelper(window).Handle; IntPtr exStyle = Win32Interop.GetWindowLongPtr(hwnd, Win32Interop.GWL_EXSTYLE); if (IntPtr.Size == 4) { exStyle = new IntPtr(exStyle.ToInt32() | Win32Interop.WS_EX_DLGMODALFRAME); } else { exStyle = new IntPtr(exStyle.ToInt64() | ((long)Win32Interop.WS_EX_DLGMODALFRAME)); } Win32Interop.SetWindowLongPtr(new HandleRef(window, hwnd), Win32Interop.GWL_EXSTYLE, exStyle); Win32Interop.SendMessage(hwnd, Win32Interop.WM_SETICON, new IntPtr(Win32Interop.ICON_SMALL), IntPtr.Zero); Win32Interop.SendMessage(hwnd, Win32Interop.WM_SETICON, new IntPtr(Win32Interop.ICON_BIG), IntPtr.Zero); } private static long SetBit(long mask, long value, bool flag) { if (flag) { return value | mask; } else { return value & ~mask; } } private static int SetBit(int mask, int value, bool flag) { if (flag) { return value | mask; } else { return value & ~mask; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MatrixAnimationUsingKeyFrames.cs
- ValuePatternIdentifiers.cs
- QilName.cs
- OleDbError.cs
- NullableFloatAverageAggregationOperator.cs
- SrgsElementList.cs
- WizardSideBarListControlItem.cs
- TemplateControlParser.cs
- MetadataItem.cs
- VScrollBar.cs
- EditorZoneDesigner.cs
- BitmapEffectDrawing.cs
- Documentation.cs
- EventLogEntryCollection.cs
- DbLambda.cs
- OletxDependentTransaction.cs
- Permission.cs
- ToolStripDropTargetManager.cs
- Utils.cs
- ListViewHitTestInfo.cs
- DeviceFilterEditorDialog.cs
- ConfigurationElementCollection.cs
- TextTreeNode.cs
- StringSource.cs
- TreeBuilderBamlTranslator.cs
- MetadataProperty.cs
- TaiwanCalendar.cs
- ReflectEventDescriptor.cs
- TreeNodeClickEventArgs.cs
- AuthenticateEventArgs.cs
- UriGenerator.cs
- ComplexType.cs
- BamlRecordHelper.cs
- XmlILIndex.cs
- DrawingServices.cs
- FontStyles.cs
- Deflater.cs
- IResourceProvider.cs
- TemplateInstanceAttribute.cs
- LineGeometry.cs
- StringUtil.cs
- XmlQueryContext.cs
- XmlSchemaAttributeGroupRef.cs
- XmlSerializationGeneratedCode.cs
- PersonalizationStateQuery.cs
- StateValidator.cs
- ProxyGenerationError.cs
- ProfilePropertyNameValidator.cs
- ButtonChrome.cs
- CodePageEncoding.cs
- BrowserInteropHelper.cs
- UniqueIdentifierService.cs
- RadialGradientBrush.cs
- ScriptIgnoreAttribute.cs
- WebPartCloseVerb.cs
- ConnectorRouter.cs
- CultureInfoConverter.cs
- _HTTPDateParse.cs
- sqlpipe.cs
- SqlWebEventProvider.cs
- CodeAccessSecurityEngine.cs
- ByteStorage.cs
- ByteFacetDescriptionElement.cs
- SafeNativeMethods.cs
- _BasicClient.cs
- FontEmbeddingManager.cs
- Process.cs
- RoleManagerSection.cs
- GcHandle.cs
- NumericUpDown.cs
- SQLInt32Storage.cs
- UIHelper.cs
- XPathExpr.cs
- SqlDependencyListener.cs
- ConfigurationValidatorAttribute.cs
- ResourceDictionary.cs
- ProviderIncompatibleException.cs
- DataGridLinkButton.cs
- Deserializer.cs
- WebBaseEventKeyComparer.cs
- OutputCacheSettings.cs
- EmptyTextWriter.cs
- RouteUrlExpressionBuilder.cs
- PersonalizationAdministration.cs
- CryptoConfig.cs
- ValueExpressions.cs
- InstanceCollisionException.cs
- ImageListDesigner.cs
- MediaEntryAttribute.cs
- CompilerGeneratedAttribute.cs
- RoutingEndpointTrait.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- Send.cs
- LinkedDataMemberFieldEditor.cs
- GridViewAutoFormat.cs
- RegexStringValidator.cs
- WebServiceTypeData.cs
- SystemIPGlobalStatistics.cs
- IsolatedStorageFileStream.cs
- _ServiceNameStore.cs