Example #1
0
        public static Boolean?GetMouseButtonsAreSwapped()
        {
            // first, make sure that a mouse is present
            if (Mouse.GetMouseIsPresent() == false)
            {
                return(null);
            }

            var mouseButtonsAreSwapped = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_SWAPBUTTON);

            return(mouseButtonsAreSwapped != 0 ? true : false);
        }
        //
        //public static Size? GetMainDisplayMonitorSizeInPixels_DpiAware(UInt32 dpi)
        //{
        //    var width = WindowsApi.GetSystemMetricsForDpi(WindowsApi.SystemMetricIndex.SM_CXSCREEN, dpi);
        //    var height = WindowsApi.GetSystemMetricsForDpi(WindowsApi.SystemMetricIndex.SM_CYSCREEN, dpi);
        //    if (width == 0 || height == 0)
        //    {
        //        return null;
        //    }

        //    return new Size(width, height);
        //}


        // TODO: To get the coordinates of the portion of the screen that is not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value instead
        // NOTE: this function is not DPI aware (unless the app is DPI-aware)
        public static Size?GetMainDisplayMonitorFullScreenWindowSizeInPixels()
        {
            // TODO: use alternate GetSystemMetricsForDpi in dpi-aware apps
            // NOTE: GetSystemMetrics returns a scaled DPI value (not the physical number of pixels)
            var width  = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CXFULLSCREEN);
            var height = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CYFULLSCREEN);

            if (width == 0 || height == 0)
            {
                return(null);
            }

            return(new Size(width, height));
        }
        //
        //public static Size? GetMainDisplayMonitorFullScreenWindowSizeInPixels_DpiAware(UInt32 dpi)
        //{
        //    // NOTE: GetSystemMetrics returns a scaled DPI value (not the physical number of pixels)
        //    var width = WindowsApi.GetSystemMetricsForDpi(WindowsApi.SystemMetricIndex.SM_CXFULLSCREEN, dpi);
        //    var height = WindowsApi.GetSystemMetricsForDpi(WindowsApi.SystemMetricIndex.SM_CYFULLSCREEN, dpi);
        //    if (width == 0 || height == 0)
        //    {
        //        return null;
        //    }

        //    return new Size(width, height);
        //}

        // NOTE: this function is not DPI aware (unless the app is DPI-aware)
        public static Rectangle?GetVirtualScreenBoundsInPixels()
        {
            // NOTE: GetSystemMetrics returns a scaled DPI value (not the physical number of pixels)
            var x      = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_XVIRTUALSCREEN);
            var y      = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_YVIRTUALSCREEN);
            var width  = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CXVIRTUALSCREEN);
            var height = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CYVIRTUALSCREEN);

            if (width == 0 || height == 0)
            {
                return(null);
            }

            return(new Rectangle(x, y, width, height));
        }
        // NOTE: this function is not DPI aware (unless the app is DPI-aware)
        public static Size?GetMainDisplayMonitorSizeInPixels()
        {
            // implementation option 1:
            // TODO: use alternate GetSystemMetricsForDpi in dpi-aware apps
            // NOTE: GetSystemMetrics returns a scaled DPI value (not the physical number of pixels)
            var width  = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CXSCREEN);
            var height = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CYSCREEN);

            if (width == 0 || height == 0)
            {
                return(null);
            }

            // implementation option 2:
            // TODO: ... width = GetDeviceCaps(hdcPrimaryMonitor, HORZRES);
            // TODO: ... height = GetDeviceCaps(hdcPrimaryMonitor, VERTRES);
            //if (width == 0 || height == 0)
            //{
            //    return null;
            //}

            return(new Size(width, height));
        }
Example #5
0
        // NOTE: historically, virtually all Windows machines will believe that a mouse is present: even if no mouse is plugged in, the presence of a "mouse port" can also register as presence of a mouse
        public static Boolean GetMouseIsPresent()
        {
            var mouseIsPresent = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_MOUSEPRESENT);

            return(mouseIsPresent != 0 ? true : false);
        }
        public static Int32 GetNumberOfVisibleDisplayMonitors()
        {
            var numberOfVisibleDisplayMonitors = WindowsApi.GetSystemMetrics(WindowsApi.SystemMetricIndex.SM_CMONITORS);

            return(numberOfVisibleDisplayMonitors);
        }