作者: cskin
查看: 2133|回复: 3
打印 上一主题 下一主题

[教程] 【系统操作篇】更改屏幕分辨率

[复制链接]
跳转到指定楼层
楼主
cskin 发表于 2014-8-1 21:40:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
查看: 2133|回复: 3
[C#] 纯文本查看 复制代码
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int ChangeDisplaySettings([In] ref DEVMODE lpDevMode, int dwFlags);

public enum DMDO
{
    DEFAULT = 0,
    D90 = 1,
    D180 = 2,
    D270 = 3
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
struct DEVMODE
{
    public const int DM_DISPLAYFREQUENCY = 0x400000;
    public const int DM_PELSWIDTH = 0x80000;
    public const int DM_PELSHEIGHT = 0x100000;
    public const int DM_BITSPERPEL = 262144;
    private const int CCHDEVICENAME = 32;
    private const int CCHFORMNAME = 32;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHDEVICENAME)]
    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 DMDO dmDisplayOrientation;
    public int dmDisplayFixedOutput;
    public short dmColor;
    public short dmDuplex;
    public short dmYResolution;
    public short dmTTOption;
    public short dmCollate;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CCHFORMNAME)]
    public string dmFormName;
    public short dmLogPixels;
    public int 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;
}


调用方法:
[C#] 纯文本查看 复制代码
long RetVal = 0;
DEVMODE dm = new DEVMODE();
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
dm.dmPelsWidth = 1024;//宽
dm.dmPelsHeight = 768;//高
dm.dmDisplayFrequency = 60;//刷新率
dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | DEVMODE.DM_DISPLAYFREQUENCY | DEVMODE.DM_BITSPERPEL;
RetVal = ChangeDisplaySettings(ref dm, 0);


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 转播转播
回复 论坛版权

使用道具 举报

沙发
原始 发表于 2014-8-2 14:33:18 | 只看该作者
你代码里的宽高和刷新率是自己指定的吗?
板凳
 楼主| cskin 发表于 2014-8-2 16:54:40 | 只看该作者
原始 发表于 2014-8-2 14:33
你代码里的宽高和刷新率是自己指定的吗?

嗯嗯嗯嗯嗯嗯嗯嗯嗯嗯
地板
youngtime007 发表于 2017-6-27 14:14:05 | 只看该作者
要是有自适应的分辨率就好了
您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-11-16 14:48, Processed in 0.529235 second(s), 28 queries , Gzip On.

快速回复 返回顶部 返回列表