1
using System;
2
using System.Drawing;
3
using System.Collections;
4
using System.ComponentModel;
5
using System.Windows.Forms;
6
using System.Data;
7
using System.Runtime.InteropServices;
8
9
namespace ScreenResolution
10
{
11
12
public class Form1 : System.Windows.Forms.Form
13
{
14
public enum DMDO
15
{
16
DEFAULT = 0,
17
D90 = 1,
18
D180 = 2,
19
D270 = 3
20
}
21
22
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
23
struct DEVMODE
24
{
25
public const int DM_DISPLAYFREQUENCY = 0x400000;
26
public const int DM_PELSWIDTH = 0x80000;
27
public const int DM_PELSHEIGHT = 0x100000;
28
private const int CCHDEVICENAME = 32;
29
private const int CCHFORMNAME = 32;
30
31
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHDEVICENAME)]
32
public string dmDeviceName;
33
public short dmSpecVersion;
34
public short dmDriverVersion;
35
public short dmSize;
36
public short dmDriverExtra;
37
public int dmFields;
38
39
public int dmPositionX;
40
public int dmPositionY;
41
public DMDO dmDisplayOrientation;
42
public int dmDisplayFixedOutput;
43
44
public short dmColor;
45
public short dmDuplex;
46
public short dmYResolution;
47
public short dmTTOption;
48
public short dmCollate;
49
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHFORMNAME)]
50
public string dmFormName;
51
public short dmLogPixels;
52
public int dmBitsPerPel;
53
public int dmPelsWidth;
54
public int dmPelsHeight;
55
public int dmDisplayFlags;
56
public int dmDisplayFrequency;
57
public int dmICMMethod;
58
public int dmICMIntent;
59
public int dmMediaType;
60
public int dmDitherType;
61
public int dmReserved1;
62
public int dmReserved2;
63
public int dmPanningWidth;
64
public int dmPanningHeight;
65
}
66
67
[DllImport("user32.dll", CharSet=CharSet.Auto)]
68
//static extern int ChangeDisplaySettings( DEVMODE lpDevMode, int
69
70
//dwFlags);
71
72
static extern int ChangeDisplaySettings( [In] ref DEVMODE lpDevMode,
73
74
int dwFlags);
75
private System.ComponentModel.Container components = null;
76
// [STAThread]
77
// static void Main()
78
// {
79
// Application.Run(new Form1());
80
// }
81
public Form1()
82
{
83
InitializeComponent();
84
}
85
protected override void Dispose( bool disposing )
86
{
87
if( disposing )
88
{
89
if (components != null)
90
{
91
components.Dispose();
92
}
93
}
94
base.Dispose( disposing );
95
}
96
97
Windows Form Designer generated code
106
107
static void Main()
108
{
109
Form1 r = new Form1();
110
r.ChangeRes();
111
Application.Run(new Form1());
112
}
113
114
void ChangeRes()
115
{
116
Form1 t = new Form1();
117
long RetVal=0;
118
DEVMODE dm = new DEVMODE();
119
dm.dmSize= (short)Marshal.SizeOf(typeof(DEVMODE));
120
dm.dmPelsWidth =1024;
121
dm.dmPelsHeight= 768;
122
dm.dmDisplayFrequency=85;
123
dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT |
124
125
DEVMODE.DM_DISPLAYFREQUENCY;
126
RetVal = ChangeDisplaySettings(ref dm, 0);
127
}
128
}
129
}
using System;2
using System.Drawing;3
using System.Collections;4
using System.ComponentModel;5
using System.Windows.Forms;6
using System.Data;7
using System.Runtime.InteropServices;8

9
namespace ScreenResolution10
{11

12
public class Form1 : System.Windows.Forms.Form13
{14
public enum DMDO15
{16
DEFAULT = 0,17
D90 = 1,18
D180 = 2,19
D270 = 320
}21

22
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]23
struct DEVMODE24
{25
public const int DM_DISPLAYFREQUENCY = 0x400000;26
public const int DM_PELSWIDTH = 0x80000;27
public const int DM_PELSHEIGHT = 0x100000;28
private const int CCHDEVICENAME = 32;29
private const int CCHFORMNAME = 32;30

31
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHDEVICENAME)]32
public string dmDeviceName;33
public short dmSpecVersion;34
public short dmDriverVersion;35
public short dmSize;36
public short dmDriverExtra;37
public int dmFields;38

39
public int dmPositionX;40
public int dmPositionY;41
public DMDO dmDisplayOrientation;42
public int dmDisplayFixedOutput;43

44
public short dmColor;45
public short dmDuplex;46
public short dmYResolution;47
public short dmTTOption;48
public short dmCollate;49
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHFORMNAME)]50
public string dmFormName;51
public short dmLogPixels;52
public int dmBitsPerPel;53
public int dmPelsWidth;54
public int dmPelsHeight;55
public int dmDisplayFlags;56
public int dmDisplayFrequency;57
public int dmICMMethod;58
public int dmICMIntent;59
public int dmMediaType;60
public int dmDitherType;61
public int dmReserved1;62
public int dmReserved2;63
public int dmPanningWidth;64
public int dmPanningHeight;65
}66

67
[DllImport("user32.dll", CharSet=CharSet.Auto)]68
//static extern int ChangeDisplaySettings( DEVMODE lpDevMode, int 69

70
//dwFlags);71

72
static extern int ChangeDisplaySettings( [In] ref DEVMODE lpDevMode, 73

74
int dwFlags);75
private System.ComponentModel.Container components = null;76
// [STAThread]77
// static void Main()78
// {79
// Application.Run(new Form1());80
// }81
public Form1()82
{83
InitializeComponent();84
}85
protected override void Dispose( bool disposing )86
{87
if( disposing )88
{89
if (components != null)90
{91
components.Dispose();92
}93
}94
base.Dispose( disposing );95
}96

97
Windows Form Designer generated code106

107
static void Main()108
{109
Form1 r = new Form1();110
r.ChangeRes();111
Application.Run(new Form1());112
}113

114
void ChangeRes()115
{116
Form1 t = new Form1();117
long RetVal=0;118
DEVMODE dm = new DEVMODE();119
dm.dmSize= (short)Marshal.SizeOf(typeof(DEVMODE));120
dm.dmPelsWidth =1024;121
dm.dmPelsHeight= 768;122
dm.dmDisplayFrequency=85;123
dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | 124

125
DEVMODE.DM_DISPLAYFREQUENCY;126
RetVal = ChangeDisplaySettings(ref dm, 0);127
}128
}129
}


浙公网安备 33010602011771号