Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / UIAutomation / Win32Providers / MS / Internal / AutomationProxies / CommonGetThemePartSize.cs / 1 / CommonGetThemePartSize.cs
using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using MS.Win32; namespace MS.Internal.AutomationProxies { class ThemePart: IDisposable { // ------------------------------------------------------ // // Constructors // //----------------------------------------------------- #region Constructors internal ThemePart (IntPtr hwnd, string sClass) { if (Environment.OSVersion.Version.Major >= 5) { _hTheme = new SafeThemeHandle(OpenThemeData(hwnd, sClass), false); } else { _hTheme = new SafeThemeHandle(IntPtr.Zero, false); } } public void Dispose () { _hTheme.Dispose(); } #endregion //----------------------------------------------------- // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Retreive the dimension of of UI element internal NativeMethods.SIZE Size (int iPartId, int iStateId) { bool fSuccess = false; // Default is (0, 0) NativeMethods.SIZE size = new NativeMethods.SIZE(0, 0); if (!_hTheme.IsInvalid) { unsafe { fSuccess = GetThemePartSize(_hTheme, IntPtr.Zero, iPartId, iStateId, IntPtr.Zero, (int)THEMESIZE.TS_TRUE, &size) == IntPtr.Zero; } } // Falls back uses GetSystemMetrics if (!fSuccess) { // dangerous construct, the iPartId might collide. // When entering an entry, make sure that the ID is not previously used. // If it is the case, then an extra parameter needs to be added to this method switch (iPartId) { case (int) STATUSPARTS.SP_GRIPPER: size.cx = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); size.cy = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); break; case (int)SCROLLBARPARTS.SBP_SIZEBOX: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXVSCROLL); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYHSCROLL); break; case (int)SCROLLBARPARTS.SBP_ARROWBTN: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXHSCROLL); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYVSCROLL); break; case (int) WINDOWPARTS.WP_MINBUTTON : case (int) WINDOWPARTS.WP_MAXBUTTON : case (int) WINDOWPARTS.WP_CLOSEBUTTON : case (int) WINDOWPARTS.WP_HELPBUTTON : size.cx = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); size.cy = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); break; default: System.Diagnostics.Debug.Assert (false, "Unsupport Type"); break; } } return size; } #endregion //------------------------------------------------------ // // Internal Fields // //----------------------------------------------------- #region Internal Fields internal enum WINDOWPARTS { WP_CAPTION = 1, WP_SMALLCAPTION = 2, WP_MINCAPTION = 3, WP_SMALLMINCAPTION = 4, WP_MAXCAPTION = 5, WP_SMALLMAXCAPTION = 6, WP_FRAMELEFT = 7, WP_FRAMERIGHT = 8, WP_FRAMEBOTTOM = 9, WP_SMALLFRAMELEFT = 10, WP_SMALLFRAMERIGHT = 11, WP_SMALLFRAMEBOTTOM = 12, WP_SYSBUTTON = 13, WP_MDISYSBUTTON = 14, WP_MINBUTTON = 15, WP_MDIMINBUTTON = 16, WP_MAXBUTTON = 17, WP_CLOSEBUTTON = 18, WP_SMALLCLOSEBUTTON = 19, WP_MDICLOSEBUTTON = 20, WP_RESTOREBUTTON = 21, WP_MDIRESTOREBUTTON = 22, WP_HELPBUTTON = 23, WP_MDIHELPBUTTON = 24, WP_HORZSCROLL = 25, WP_HORZTHUMB = 26, WP_VERTSCROLL = 27, WP_VERTTHUMB = 28, WP_DIALOG = 29, WP_CAPTIONSIZINGTEMPLATE = 30, WP_SMALLCAPTIONSIZINGTEMPLATE = 31, WP_FRAMELEFTSIZINGTEMPLATE = 32, WP_SMALLFRAMELEFTSIZINGTEMPLATE = 33, WP_FRAMERIGHTSIZINGTEMPLATE = 34, WP_SMALLFRAMERIGHTSIZINGTEMPLATE = 35, WP_FRAMEBOTTOMSIZINGTEMPLATE = 36, WP_SMALLFRAMEBOTTOMSIZINGTEMPLATE = 37, }; // internal enum MINBUTTONSTATES { MINBS_NORMAL = 1, MINBS_HOT = 2, MINBS_PUSHED = 3, MINBS_DISABLED = 4, }; internal enum SCROLLBARPARTS { SBP_ARROWBTN = 1, SBP_THUMBBTNHORZ = 2, SBP_THUMBBTNVERT = 3, SBP_LOWERTRACKHORZ = 4, SBP_UPPERTRACKHORZ = 5, SBP_LOWERTRACKVERT = 6, SBP_UPPERTRACKVERT = 7, SBP_GRIPPERHORZ = 8, SBP_GRIPPERVERT = 9, SBP_SIZEBOX = 10, }; internal enum STATUSPARTS { SP_PANE = 1, SP_GRIPPERPANE = 2, SP_GRIPPER = 3, }; enum THEMESIZE { TS_MIN, // minimum size TS_TRUE, // size without stretching TS_DRAW, // size that theme mgr will use to draw part }; #endregion //------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods [DllImport ("UxTheme.dll", CharSet = CharSet.Auto)] private static unsafe extern IntPtr GetThemePartSize(SafeThemeHandle hTheme, IntPtr hdc, int iPartId, int iStateId, IntPtr prc, int eSize, NativeMethods.SIZE* psz); [DllImport ("UxTheme.dll", CharSet = CharSet.Auto)] private static extern IntPtr OpenThemeData(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)]string s); #endregion //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields // cached Value. Will never be initialize elsewhere if OS == Win98 private SafeThemeHandle _hTheme; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Security; using System.Security.Permissions; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using Microsoft.Win32.SafeHandles; using MS.Win32; namespace MS.Internal.AutomationProxies { class ThemePart: IDisposable { // ------------------------------------------------------ // // Constructors // //----------------------------------------------------- #region Constructors internal ThemePart (IntPtr hwnd, string sClass) { if (Environment.OSVersion.Version.Major >= 5) { _hTheme = new SafeThemeHandle(OpenThemeData(hwnd, sClass), false); } else { _hTheme = new SafeThemeHandle(IntPtr.Zero, false); } } public void Dispose () { _hTheme.Dispose(); } #endregion //----------------------------------------------------- // // Internal Methods // //----------------------------------------------------- #region Internal Methods // Retreive the dimension of of UI element internal NativeMethods.SIZE Size (int iPartId, int iStateId) { bool fSuccess = false; // Default is (0, 0) NativeMethods.SIZE size = new NativeMethods.SIZE(0, 0); if (!_hTheme.IsInvalid) { unsafe { fSuccess = GetThemePartSize(_hTheme, IntPtr.Zero, iPartId, iStateId, IntPtr.Zero, (int)THEMESIZE.TS_TRUE, &size) == IntPtr.Zero; } } // Falls back uses GetSystemMetrics if (!fSuccess) { // dangerous construct, the iPartId might collide. // When entering an entry, make sure that the ID is not previously used. // If it is the case, then an extra parameter needs to be added to this method switch (iPartId) { case (int) STATUSPARTS.SP_GRIPPER: size.cx = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); size.cy = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); break; case (int)SCROLLBARPARTS.SBP_SIZEBOX: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXVSCROLL); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYHSCROLL); break; case (int)SCROLLBARPARTS.SBP_ARROWBTN: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXHSCROLL); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYVSCROLL); break; case (int) WINDOWPARTS.WP_MINBUTTON : case (int) WINDOWPARTS.WP_MAXBUTTON : case (int) WINDOWPARTS.WP_CLOSEBUTTON : case (int) WINDOWPARTS.WP_HELPBUTTON : size.cx = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); size.cy = UnsafeNativeMethods.GetSystemMetrics (NativeMethods.SM_CXSIZE); break; default: System.Diagnostics.Debug.Assert (false, "Unsupport Type"); break; } } return size; } #endregion //------------------------------------------------------ // // Internal Fields // //----------------------------------------------------- #region Internal Fields internal enum WINDOWPARTS { WP_CAPTION = 1, WP_SMALLCAPTION = 2, WP_MINCAPTION = 3, WP_SMALLMINCAPTION = 4, WP_MAXCAPTION = 5, WP_SMALLMAXCAPTION = 6, WP_FRAMELEFT = 7, WP_FRAMERIGHT = 8, WP_FRAMEBOTTOM = 9, WP_SMALLFRAMELEFT = 10, WP_SMALLFRAMERIGHT = 11, WP_SMALLFRAMEBOTTOM = 12, WP_SYSBUTTON = 13, WP_MDISYSBUTTON = 14, WP_MINBUTTON = 15, WP_MDIMINBUTTON = 16, WP_MAXBUTTON = 17, WP_CLOSEBUTTON = 18, WP_SMALLCLOSEBUTTON = 19, WP_MDICLOSEBUTTON = 20, WP_RESTOREBUTTON = 21, WP_MDIRESTOREBUTTON = 22, WP_HELPBUTTON = 23, WP_MDIHELPBUTTON = 24, WP_HORZSCROLL = 25, WP_HORZTHUMB = 26, WP_VERTSCROLL = 27, WP_VERTTHUMB = 28, WP_DIALOG = 29, WP_CAPTIONSIZINGTEMPLATE = 30, WP_SMALLCAPTIONSIZINGTEMPLATE = 31, WP_FRAMELEFTSIZINGTEMPLATE = 32, WP_SMALLFRAMELEFTSIZINGTEMPLATE = 33, WP_FRAMERIGHTSIZINGTEMPLATE = 34, WP_SMALLFRAMERIGHTSIZINGTEMPLATE = 35, WP_FRAMEBOTTOMSIZINGTEMPLATE = 36, WP_SMALLFRAMEBOTTOMSIZINGTEMPLATE = 37, }; // internal enum MINBUTTONSTATES { MINBS_NORMAL = 1, MINBS_HOT = 2, MINBS_PUSHED = 3, MINBS_DISABLED = 4, }; internal enum SCROLLBARPARTS { SBP_ARROWBTN = 1, SBP_THUMBBTNHORZ = 2, SBP_THUMBBTNVERT = 3, SBP_LOWERTRACKHORZ = 4, SBP_UPPERTRACKHORZ = 5, SBP_LOWERTRACKVERT = 6, SBP_UPPERTRACKVERT = 7, SBP_GRIPPERHORZ = 8, SBP_GRIPPERVERT = 9, SBP_SIZEBOX = 10, }; internal enum STATUSPARTS { SP_PANE = 1, SP_GRIPPERPANE = 2, SP_GRIPPER = 3, }; enum THEMESIZE { TS_MIN, // minimum size TS_TRUE, // size without stretching TS_DRAW, // size that theme mgr will use to draw part }; #endregion //------------------------------------------------------ // // Private Methods // //------------------------------------------------------ #region Private Methods [DllImport ("UxTheme.dll", CharSet = CharSet.Auto)] private static unsafe extern IntPtr GetThemePartSize(SafeThemeHandle hTheme, IntPtr hdc, int iPartId, int iStateId, IntPtr prc, int eSize, NativeMethods.SIZE* psz); [DllImport ("UxTheme.dll", CharSet = CharSet.Auto)] private static extern IntPtr OpenThemeData(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)]string s); #endregion //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields // cached Value. Will never be initialize elsewhere if OS == Win98 private SafeThemeHandle _hTheme; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BatchParser.cs
- EntityDataSourceState.cs
- ClonableStack.cs
- FontCacheUtil.cs
- PositiveTimeSpanValidatorAttribute.cs
- PartDesigner.cs
- SecurityTokenValidationException.cs
- TextOnlyOutput.cs
- FrameworkContentElement.cs
- LateBoundBitmapDecoder.cs
- NegotiationTokenAuthenticator.cs
- RecommendedAsConfigurableAttribute.cs
- WeakReferenceEnumerator.cs
- HttpHandlerActionCollection.cs
- BadImageFormatException.cs
- WebPartZone.cs
- EventRoute.cs
- BaseParagraph.cs
- Location.cs
- ContainerParagraph.cs
- SetterBase.cs
- Header.cs
- TextCharacters.cs
- ScanQueryOperator.cs
- StylusShape.cs
- StringAnimationBase.cs
- SecurityTraceRecordHelper.cs
- RecognizedAudio.cs
- SudsWriter.cs
- WebServiceClientProxyGenerator.cs
- DataContext.cs
- XsltSettings.cs
- HostVisual.cs
- MetafileEditor.cs
- Pair.cs
- BamlResourceSerializer.cs
- mactripleDES.cs
- DocumentDesigner.cs
- ErrorInfoXmlDocument.cs
- SubstitutionDesigner.cs
- SoapSchemaExporter.cs
- XmlExpressionDumper.cs
- ImageMap.cs
- DataGridViewComboBoxEditingControl.cs
- ReadOnlyDictionary.cs
- EntryWrittenEventArgs.cs
- documentsequencetextview.cs
- Html32TextWriter.cs
- ReleaseInstanceMode.cs
- DataColumnMappingCollection.cs
- MachineKeySection.cs
- EditorServiceContext.cs
- NodeCounter.cs
- TextTreeInsertUndoUnit.cs
- CodeArrayIndexerExpression.cs
- SafeMILHandle.cs
- SchemaNamespaceManager.cs
- Attribute.cs
- ArglessEventHandlerProxy.cs
- RegexCompilationInfo.cs
- ApplicationDirectoryMembershipCondition.cs
- Semaphore.cs
- FlowDocumentPageViewerAutomationPeer.cs
- MobileUserControlDesigner.cs
- Adorner.cs
- SafeCertificateContext.cs
- TCPClient.cs
- XmlBoundElement.cs
- FillBehavior.cs
- ListViewContainer.cs
- WindowsListViewScroll.cs
- Exception.cs
- WasAdminWrapper.cs
- RequestCacheValidator.cs
- InlineUIContainer.cs
- PhysicalAddress.cs
- PointAnimationUsingPath.cs
- DictionaryBase.cs
- DBParameter.cs
- SafeRegistryHandle.cs
- ObjectListComponentEditor.cs
- RouteParameter.cs
- WebBrowserContainer.cs
- BitmapFrameDecode.cs
- CryptoStream.cs
- NGCPageContentCollectionSerializerAsync.cs
- LinqDataView.cs
- Message.cs
- RestClientProxyHandler.cs
- WriteableBitmap.cs
- MobileUITypeEditor.cs
- DictionaryContent.cs
- RadioButtonDesigner.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- ServiceThrottlingBehavior.cs
- EndpointDiscoveryMetadataCD1.cs
- sqlinternaltransaction.cs
- DeclarativeConditionsCollection.cs
- Int64Animation.cs
- SessionParameter.cs