- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace ScrDPI
- {
- public class ScrDPI
- {
- public enum SETSTATUS
- {
- /// <summary>
- /// The settings change was successful
- /// </summary>
- DISP_CHANGE_SUCCESSFUL = 0,
- /// <summary>
- /// The computer must be restarted for
- /// the graphics mode to work.
- /// </summary>
- DISP_CHANGE_RESTART = 1,
- /// <summary>
- /// The display driver failed the
- /// specified graphics mode.
- /// </summary>
- DISP_CHANGE_FAILED = -1,
- /// <summary>
- /// The graphics mode is not supported.
- /// </summary>
- DISP_CHANGE_BADMODE = -2,
- /// <summary>
- /// Unable to write settings to
- /// the registry.
- /// </summary>
- DISP_CHANGE_NOTUPDATED = -3,
- /// <summary>
- /// An invalid set of flags was
- /// passed in.
- /// </summary>
- DISP_CHANGE_BADFLAGS = -4,
- /// <summary>
- /// An invalid parameter was passed in.
- /// This can include an invalid flag or
- /// combination of flags.
- /// </summary>
- DISP_CHANGE_BADPARAM = -5,
- /// <summary>
- /// The settings change was unsuccessful
- /// because the system is DualView capable.
- /// </summary>
- DISP_CHANGE_BADDUALVIEW = -6
- }
- [DllImport("ScrDPI.dll", CallingConvention = CallingConvention.Cdecl)]
- private extern static int SetDPI(UInt32 dwWidth, UInt32 dwHeight, UInt32 dwColor);
- /// <summary>
- /// [否决的]判断设置的结果
- /// </summary>
- /// <param name="i">SetDPI返回结果值</param>
- [DllImport("ScrDPI.dll", CallingConvention = CallingConvention.Cdecl)]
- public extern static void TellMeResult(int i);
- /// <summary>
- /// 设置屏幕分辨率
- /// </summary>
- /// <param name="dwWidth">宽</param>
- /// <param name="dwHeight">高</param>
- /// <param name="dwColor">颜色</param>
- /// <returns></returns>
- public static SETSTATUS SetScreenDPI(UInt32 dwWidth, UInt32 dwHeight, UInt32 dwColor)
- {
- return (SETSTATUS)SetDPI(dwWidth, dwHeight, dwColor);
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0807201513059.html
来源: http://www.codesnippet.cn/detail/0807201513059.html