国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

C#中改變顯示器的分辨率和刷新率

2024-07-21 02:27:05
字體:
供稿:網(wǎng)友

下面的代碼實現(xiàn)修改顯示器分辨率和刷新頻率的功能:

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.runtime.interopservices;

namespace screenresolution
{

  public class form1 : system.windows.forms.form
  {
    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;
      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;
    }

    [dllimport("user32.dll", charset=charset.auto)]
      //static extern int changedisplaysettings( devmode lpdevmode,  int dwflags);

    static extern int changedisplaysettings( [in] ref devmode lpdevmode,  int dwflags);
    private system.componentmodel.container components = null;
    public form1()
    {
      initializecomponent();
    }
    protected override void dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null)
        {
          components.dispose();
        }
      }
      base.dispose( disposing );
    }

    windows form designer generated code#region windows form designer generated code
    private void initializecomponent()
    {
      this.autoscalebasesize = new system.drawing.size(6, 14);
      this.clientsize = new system.drawing.size(292, 273);
      this.text = "改變屏幕分辨率的例子";

    }
    #endregion

    static void main()
    {
      form1 r = new form1();
      r.changeres();
      application.run(new form1());
    }

    void changeres()
    {
      form1 t = new form1();
      long retval=0;
      devmode dm = new devmode();
      dm.dmsize= (short)marshal.sizeof(typeof(devmode));
      dm.dmpelswidth = 1024;
      dm.dmpelsheight= 768;
      dm.dmdisplayfrequency=85;
      dm.dmfields = devmode.dm_pelswidth | devmode.dm_pelsheight | devmode.dm_displayfrequency;
      retval = changedisplaysettings(ref dm, 0);
    }
  }
}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 望谟县| 长兴县| 西林县| 施秉县| 托里县| 兴安县| 龙岩市| 宜君县| 沁源县| 苍南县| 咸宁市| 新化县| 虎林市| 基隆市| 白朗县| 宜良县| 罗山县| 芷江| 咸丰县| 长白| 乐安县| 浦县| 宜阳县| 改则县| 桐梓县| 遂溪县| 隆尧县| 合阳县| 金阳县| 祥云县| 淄博市| 和平区| 台南市| 郓城县| 拉萨市| 固安县| 华容县| 古田县| 灌云县| 晋江市| 晋江市|