c# – 如何在Windows 7中设置显示器方向?

c# – 如何在Windows 7中设置显示器方向?,第1张

概述我想写一些有趣的代码在 Windows 7上翻转方向.请参阅我想要控制的选项的屏幕截图. 这是我的代码: class Program{ public const long WM_PAINT=0x0F; public const long WM_DISPLAYCHANGE=0x7E; [StructLayout(LayoutKind.Sequential, CharSet 我想写一些有趣的代码在 Windows 7上翻转方向.请参阅我想要控制的选项的屏幕截图.

这是我的代码:

class Program{    public const long WM_PAINT=0x0F;    public const long WM_disPLAYCHANGE=0x7E;    [StructLayout(LayoutKind.Sequential,CharSet=CharSet.@R_419_6843@)]    public struct DEVMODE // taken from Win API    {        ...        public System.windows.Forms.ScreenorIEntation dmdisplayOrIEntation;    }    [Dllimport("user32.dll",CharSet=CharSet.@R_419_6843@)]    public static extern bool EnumdisplaySettings(string lpszDevicename,int iModeNum,ref DEVMODE lpDevMode);    [Dllimport("user32.dll",CharSet=CharSet.Ansi)]    public static extern int ChangedisplaySettings(ref DEVMODE lpDevMode,int DWFlags);    [Dllimport("User32.Dll")]    public static extern long PostMessage(IntPtr hWnd,long wMsg,long wParam,long lParam);    static voID Main(string[] args)    {        ScreenorIEntation ori=ScreenorIEntation.Angle0;        DEVMODE mode=new DEVMODE()        {            dmSize=(short)Marshal.SizeOf(typeof(DEVMODE)),dmDriverExtra=0,dmDevicename=new string(new char[32]),dmFormname=new string(new char[32]),};        try        {            EnumdisplaySettings(null,-1,ref mode);            if((mode.dmFIElds&0x80)>0)            {                ori=mode.dmdisplayOrIEntation;            }            mode.dmdisplayOrIEntation=ScreenorIEntation.Angle270;            int temp=mode.dmPelsWIDth;            mode.dmPelsWIDth=mode.dmPelsHeight;            mode.dmPelsHeight=temp;            int ret=ChangedisplaySettings(ref mode,0);            PostMessage(Process.GetCurrentProcess().Handle,WM_disPLAYCHANGE,0);            ...        }        catch        {        }    }}

哪个运行,但不会产生任何影响.

参考代码:http://justlikeamagic.com/2009/05/21/changing-display-settings-programmatically/
和http://msdn.microsoft.com/en-us/library/ms812499.aspx#tbconchgscrn_chngingdisplay

解决方法 我已经开始了.

请看看:MultiMonitorHelper

它包含Win7的必要结构,因此您可以调用SetdisplayConfig和其他函数.

一个实际的例子,如何将显示器旋转90度:

int numPathArrayElements;        int numModeInfoArrayElements;        const querydisplayFlags pathType = querydisplayFlags.OnlyActivePaths;        // query active paths from the current computer.        // note that 0 is equal to SUCCESS!        // Todo; HARDCODE MAGIC VALUES AWAY.        if (CCDWrapper.GetdisplayConfigBufferSizes(pathType,out numPathArrayElements,out numModeInfoArrayElements) == 0)        {            var pathInfoArray = new displayConfigPathInfo[numPathArrayElements];            var modeInfoArray = new displayConfigModeInfo[numModeInfoArrayElements];            // Todo; FALLBACK MECHANISM THAT HANDLES DIFFERENT VALUES FOR ZERO.            if (CCDWrapper.querydisplayConfig(                pathType,ref numPathArrayElements,pathInfoArray,ref numModeInfoArrayElements,modeInfoArray,IntPtr.Zero) == 0)            {                pathInfoArray[0].targetInfo.rotation = displayConfigRotation.Rotate90;                CCDWrapper.SetdisplayConfig((uint) numPathArrayElements,(uint) numModeInfoArrayElements,SdcFlags.Apply | SdcFlags.UseSupplIEddisplayConfig);            }         }

它现在是原始的,这意味着现在没有“C#style”API,但是,你可以使用这些结构.

总结

以上是内存溢出为你收集整理的c# – 如何在Windows 7中设置显示器方向?全部内容,希望文章能够帮你解决c# – 如何在Windows 7中设置显示器方向?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1243286.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存