示例#1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="DpiAwarenessScope"/> class, and sets the current thread's
            /// DPI_AWARENESS_CONTEXT to the value requested by <paramref name="dpiAwarenessContextValue"/>
            /// </summary>
            /// <param name="dpiAwarenessContextValue">New DPI awareness value</param>
            /// <param name="updateIfThreadInMixedHostingMode">When true, the current thread is switched to the new mode iff the current thread is already in mixed hosting mode</param>
            /// <param name="updateIfWindowIsSystemAwareOrUnaware">When true, the current thread is switched to the new mode iff <paramref name="hWnd"/> is in System Aware or Unaware DPI mode</param>
            /// <param name="hWnd">Window which is tested in conjunction with <paramref name="updateIfWindowIsSystemAwareOrUnaware"/></param>
            private DpiAwarenessScope(
                DpiAwarenessContextValue dpiAwarenessContextValue,
                bool updateIfThreadInMixedHostingMode,
                bool updateIfWindowIsSystemAwareOrUnaware,
                IntPtr hWnd)
            {
                if (!OperationSupported)
                {
                    return;
                }

                if (updateIfThreadInMixedHostingMode && !this.IsThreadInMixedHostingBehavior)
                {
                    return;
                }

                if (updateIfWindowIsSystemAwareOrUnaware &&
                    (hWnd == IntPtr.Zero || !this.IsWindowUnawareOrSystemAware(hWnd)))
                {
                    return;
                }

                try
                {
                    this.OldDpiAwarenessContext =
                        UnsafeNativeMethods.SetThreadDpiAwarenessContext(
                            new DpiAwarenessContextHandle(dpiAwarenessContextValue));
                }
                catch (Exception e) when(e is EntryPointNotFoundException || e is MissingMethodException || e is DllNotFoundException)
                {
                    OperationSupported = false;
                }
            }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DpiAwarenessScope"/> class, and sets the current thread's
 /// DPI_AWARENESS_CONTEXT to the value requested by <paramref name="dpiAwarenessContextEnumValue"/>
 /// </summary>
 /// <param name="dpiAwarenessContextEnumValue">DPI_AWARENESS_CONTEXT to set the thread to</param>
 public DpiAwarenessScope(DpiAwarenessContextValue dpiAwarenessContextEnumValue)
     : this(
         dpiAwarenessContextEnumValue,
         updateIfThreadInMixedHostingMode : false,
         updateIfWindowIsSystemAwareOrUnaware : false,
         hWnd : IntPtr.Zero)
 {
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DpiAwarenessScope"/> class, and sets the current thread's
 /// DPI_AWARENESS_CONTEXT to the value requested by <paramref name="dpiAwarenessContextEnumValue"/>
 /// </summary>
 /// <param name="dpiAwarenessContextEnumValue">New DPI awareness value</param>
 /// <param name="updateIfThreadInMixedHostingMode">
 /// When true, checks whether the current thread is in mixed hosting mode,
 /// and only then switches the thread to the new mode
 /// </param>
 /// <param name="hWnd">
 /// The window which is tested to see whether it is in mixed hosting mode.
 /// Only if the window is found to be in mixed hosting mode is the current threads DPI awareness context
 /// switched to the new value
 /// </param>
 public DpiAwarenessScope(
     DpiAwarenessContextValue dpiAwarenessContextEnumValue, bool updateIfThreadInMixedHostingMode, IntPtr hWnd)
     : this(
         dpiAwarenessContextEnumValue,
         updateIfThreadInMixedHostingMode : updateIfThreadInMixedHostingMode,
         updateIfWindowIsSystemAwareOrUnaware : true,
         hWnd : hWnd)
 {
 }
示例#4
0
文件: DpiUtil.cs 项目: beda2280/wpf-1
 /// <summary>
 /// Helper to modify the DPI_AWARENESS_CONTEXT of the current thread.
 /// </summary>
 /// <param name="dpiAwarenessContext">DPI_AWARENESS_CONTEXT to set the thread to</param>
 /// <returns>
 /// An <see cref="IDisposable"/> that defines a scope during which the DPI_AWARENESS_CONTEXT of the current thread is
 /// modified to the requested value.
 /// </returns>
 internal static IDisposable WithDpiAwarenessContext(DpiAwarenessContextValue dpiAwarenessContext)
 {
     return(new DpiAwarenessScope(dpiAwarenessContext));
 }
 internal DpiAwarenessContextHandle(DpiAwarenessContextValue dpiAwarenessContextValue)
     : base(WellKnownContextValues[dpiAwarenessContextValue], false)
 {
 }
 /// <summary>
 /// Equality comparison
 /// </summary>
 /// <param name="dpiContextEnumValue">DPI context enumeration value being compared against</param>
 /// <returns>True if equivalent to the DPI context enum value, otherwise False</returns>
 public bool Equals(DpiAwarenessContextValue dpiContextEnumValue)
 {
     return(this.Equals(WellKnownContextValues[dpiContextEnumValue]));
 }