技术资讯

餐饮收银软件开发:c#下利用winAPI来实现扩展屏的分辨率设置、方向切换等

TIME:2018-09-29

1、背景:头显设备连接电脑作为扩展屏使用,由于显示屏厂家的原因,拿过来初始脸上电脑的话是横向的,需要手动控制去设置成纵向,这样做成产品的话,体验比较差;

在网上找到了一种方法利用 ChangeDisplaySettingsEx配合DEVMODE结构体来实现上述功能;

            [DllImport("user32.dll")]
            public static extern bool EnumDisplayDevices(string lpDevice, int iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, int dwFlags);//获取屏幕信息
            [DllImport("user32.dll")]
            public static extern int ChangeDisplaySettingsEx(string lpszDeviceName, [In] ref DEVMODE lpDevMode, IntPtr hwnd, int dwFlags, IntPtr lParam); //设置横竖屏
            [DllImport("user32.dll", CharSet = CharSet.Unicode)]
            private static extern long SetDisplayConfig(uint numPathArrayElements,IntPtr pathArray, uint numModeArrayElements, IntPtr modeArray, uint flags);  //这个函数用于设置屏幕的复制模式、或者扩展模式;

    public struct DEVMODE
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string dmDeviceName;

            public short dmSpecVersion;
            public short dmDriverVersion;
            public short dmSize;
            public short dmDriverExtra;
            public int dmFields;
            public int dmPositionX;
            public int dmPositionY;
           // public Point dmPosition;
            public int dmDisplayOrientation;
            public int dmDisplayFixedOutput;
            public short dmColor;
            public short dmDuplex;
            public short dmYResolution;
            public short dmTTOption;
            public short dmCollate;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string dmFormName;

            public short dmLogPixels;
            public short dmBitsPerPel;
            public int dmPelsWidth;
            public int dmPelsHeight;
            public int dmDisplayFlags;
            public int dmDisplayFrequency;
            public int dmICMMethod;
            public int dmICMIntent;
            public int dmMediaType;
            public int dmDitherType;
            public int dmReserved1;
            public int dmReserved2;
            public int dmPanningWidth;
            public int dmPanningHeight;
        };

--------------------- 本文来自 bossaiaboy 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/bossaiaboy/article/details/50525029?utm_source=copy 

上一篇

软件开发:python爬虫-Requests模块

下一篇

双屏收银软件开发:C# 将应用程序显示在扩展桌面
版权信息:Copyright (c) 2014 All rights reserved 秦皇岛时讯科技有限公司. 冀ICP备09010373号