Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / UIAutomation / Win32Providers / MS / Internal / AutomationProxies / CommonGetThemePartSize.cs / 1305600 / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlSecureResolver.cs
- PermissionSetTriple.cs
- SelectionProviderWrapper.cs
- FlowDocumentReaderAutomationPeer.cs
- SoapHeaders.cs
- StopStoryboard.cs
- DataGridLengthConverter.cs
- StylusTip.cs
- LayoutSettings.cs
- WebBrowserHelper.cs
- ReachDocumentReferenceCollectionSerializerAsync.cs
- UrlAuthFailedErrorFormatter.cs
- DbConnectionOptions.cs
- IntranetCredentialPolicy.cs
- WebServiceResponseDesigner.cs
- ModelVisual3D.cs
- ContextProperty.cs
- AspCompat.cs
- ConfigXmlText.cs
- DeflateEmulationStream.cs
- MutexSecurity.cs
- InlineObject.cs
- SequenceNumber.cs
- TdsEnums.cs
- TextElementAutomationPeer.cs
- CompatibleIComparer.cs
- GroupAggregateExpr.cs
- DataGridColumnHeaderAutomationPeer.cs
- ITextView.cs
- SocketElement.cs
- PropertyGridEditorPart.cs
- KeyConstraint.cs
- PropertyItemInternal.cs
- Stack.cs
- QuadTree.cs
- ConsoleTraceListener.cs
- KeysConverter.cs
- CannotUnloadAppDomainException.cs
- QueryParameter.cs
- TimeoutValidationAttribute.cs
- ExpressionBindingCollection.cs
- XmlNamespaceDeclarationsAttribute.cs
- XAMLParseException.cs
- MembershipSection.cs
- BoolExpr.cs
- SourceElementsCollection.cs
- mediaeventargs.cs
- OdbcConnectionHandle.cs
- SelectionPattern.cs
- EndpointDiscoveryMetadata.cs
- AspProxy.cs
- DataTableMappingCollection.cs
- ISCIIEncoding.cs
- FullTextBreakpoint.cs
- RichTextBox.cs
- InheritanceContextChangedEventManager.cs
- ApplicationActivator.cs
- KeyNotFoundException.cs
- Soap12ProtocolImporter.cs
- PointAnimationClockResource.cs
- ImageButton.cs
- CanonicalizationDriver.cs
- WorkflowFileItem.cs
- MetadataItemEmitter.cs
- PropertyKey.cs
- SessionStateUtil.cs
- ObjectDisposedException.cs
- SelectionBorderGlyph.cs
- WebResourceUtil.cs
- SmtpSection.cs
- QuarticEase.cs
- AlignmentXValidation.cs
- TemplateBuilder.cs
- MultiPageTextView.cs
- CalendarModeChangedEventArgs.cs
- SqlUserDefinedAggregateAttribute.cs
- ControlCollection.cs
- SQLBytes.cs
- DataList.cs
- isolationinterop.cs
- BamlLocalizabilityResolver.cs
- XmlSchemaValidationException.cs
- ToolStripRenderer.cs
- ELinqQueryState.cs
- XmlSchemaAttributeGroup.cs
- UpdateEventArgs.cs
- PermissionSetTriple.cs
- Message.cs
- FormCollection.cs
- CodeDOMUtility.cs
- EmulateRecognizeCompletedEventArgs.cs
- ListBoxItem.cs
- EqualityComparer.cs
- ScaleTransform.cs
- ChangeNode.cs
- WebEvents.cs
- InitializationEventAttribute.cs
- DeclaredTypeElementCollection.cs
- AsyncWaitHandle.cs
- Activity.cs