Example #1
0
        /// <summary>
        ///  Static ctor.  We just set up a few per-process globals here
        /// </summary>
        static ComponentManagerBroker()
        {
            int pid = SafeNativeMethods.GetCurrentProcessId();

            _syncObject       = new object();
            _remoteObjectName = string.Format(CultureInfo.CurrentCulture, "ComponentManagerBroker.{0}.{1:X}", Application.WindowsFormsVersion, pid);
        }
Example #2
0
        internal static void InitializeDpiHelperForWinforms()
        {
            if (s_isInitializeDpiHelperForWinforms)
            {
                return;
            }

            // initialize shared fields
            Initialize();

            if (OsVersion.IsWindows10_1607OrGreater)
            {
                // We are on Windows 10/1603 or greater, but we could still be DpiUnaware or SystemAware, so let's find that out...
                var    currentProcessId = SafeNativeMethods.GetCurrentProcessId();
                IntPtr hProcess         = SafeNativeMethods.OpenProcess(SafeNativeMethods.PROCESS_QUERY_INFORMATION, false, currentProcessId);
                SafeNativeMethods.GetProcessDpiAwareness(hProcess, out CAPS.PROCESS_DPI_AWARENESS processDpiAwareness);

                // Only if we're not, it makes sense to query for PerMonitorV2 awareness from now on, if needed.
                if (!(processDpiAwareness == CAPS.PROCESS_DPI_AWARENESS.PROCESS_DPI_UNAWARE ||
                      processDpiAwareness == CAPS.PROCESS_DPI_AWARENESS.PROCESS_SYSTEM_DPI_AWARE))
                {
                    s_doesNeedQueryForPerMonitorV2Awareness = true;
                }
            }

            if (IsScalingRequired || s_doesNeedQueryForPerMonitorV2Awareness)
            {
                s_isScalingRequirementMet = true;
            }

            s_isInitializeDpiHelperForWinforms = true;
        }
Example #3
0
        internal static void InitializeDpiHelperForWinforms()
        {
            if (isInitializeDpiHelperForWinforms)
            {
                return;
            }

            // initialize shared fields
            Initialize();

            // We are in Windows 10/1603 or greater when this API is present.
            if (ApiHelper.IsApiAvailable(ExternDll.User32, nameof(CommonUnsafeNativeMethods.GetThreadDpiAwarenessContext)))
            {
                // We are on Windows 10/1603 or greater all right, but we could still be DpiUnaware or SystemAware, so let's find that out...
                var    currentProcessId = SafeNativeMethods.GetCurrentProcessId();
                IntPtr hProcess         = SafeNativeMethods.OpenProcess(SafeNativeMethods.PROCESS_QUERY_INFORMATION, false, currentProcessId);
                var    result           = SafeNativeMethods.GetProcessDpiAwareness(hProcess, out CAPS.PROCESS_DPI_AWARENESS processDpiAwareness);

                // Only if we're not, it makes sense to query for PerMonitorV2 awareness from now on, if needed.
                if (!(processDpiAwareness == CAPS.PROCESS_DPI_AWARENESS.PROCESS_DPI_UNAWARE ||
                      processDpiAwareness == CAPS.PROCESS_DPI_AWARENESS.PROCESS_SYSTEM_DPI_AWARE))
                {
                    doesNeedQueryForPerMonitorV2Awareness = true;
                }
            }

            if (IsScalingRequired || doesNeedQueryForPerMonitorV2Awareness)
            {
                isScalingRequirementMet = true;
            }

            isInitializeDpiHelperForWinforms = true;
        }