using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
using system.runtime.interopservices;
namespace 解决分辨率
{
public partial class form1 : form
{
//保存当前屏幕分辨率
int i = screen.primaryscreen.bounds.width;
int j = screen.primaryscreen.bounds.height;
public form1()
{
initializecomponent();
}
[structlayout(layoutkind.sequential, charset = charset.auto)]
public struct devmode
{
[marshalas(unmanagedtype.byvaltstr, sizeconst = 32)]
public string dmdevicename;
public short dmspecversion;
public short dmdriverversion;
public short dmsize;
public short dmdriverextra;
public int dmfields;
public short dmorientation;
public short dmpapersize;
public short dmpaperlength;
public short dmpaperwidth;
public short dmscale;
public short dmcopies;
public short dmdefaultsource;
public short dmprintquality;
public short dmcolor;
public short dmduplex;
public short dmyresolution;
public short dmttoption;
public short dmcollate;
[marshalas(unmanagedtype.byvaltstr, sizeconst = 32)]
public string dmformname;
public short dmlogpixels;
public int dmbitsperpel;
public int dmpelswidth;
public int dmpelsheight;
public int dmdisplayflags;
public int dmdisplayfrequency;
}
[dllimport("user32.dll", charset = charset.auto)]
static extern int changedisplaysettings([in] ref devmode lpdevmode, int dwflags);
[dllimport("user32.dll", charset = charset.auto)]
static extern bool enumdisplaysettings(string lpszdevicename, int32 imodenum, ref devmode lpdevmode);
void changeres()
{
devmode devm = new devmode();
devm.dmsize = (short)marshal.sizeof(typeof(devmode));
bool mybool;
mybool = enumdisplaysettings(null, 0, ref devm);
devm.dmpelswidth = 1024;//宽
devm.dmpelsheight = 768;//高
devm.dmdisplayfrequency = 60;//刷新频率
devm.dmbitsperpel = 32;//颜色象素
long result = changedisplaysettings(ref devm, 0);
}
void fuyuan()
{
devmode devm = new devmode();
devm.dmsize = (short)marshal.sizeof(typeof(devmode));
bool mybool;
mybool = enumdisplaysettings(null, 0, ref devm);
devm.dmpelswidth = i;//恢复宽
devm.dmpelsheight =j;//恢复高
devm.dmdisplayfrequency = 60;//刷新频率
devm.dmbitsperpel = 32;//颜色象素
long result = changedisplaysettings(ref devm, 0);
}
private void form1_load(object sender, eventargs e)
{
changeres();
}
private void button1_click(object sender, eventargs e)
{
fuyuan();
this.close();
}
0
0
本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门AI工具
相关专题
C++ 高级模板编程与元编程
本专题深入讲解 C++ 中的高级模板编程与元编程技术,涵盖模板特化、SFINAE、模板递归、类型萃取、编译时常量与计算、C++17 的折叠表达式与变长模板参数等。通过多个实际示例,帮助开发者掌握 如何利用 C++ 模板机制编写高效、可扩展的通用代码,并提升代码的灵活性与性能。
10
2026.01.23
Golang 性能分析与pprof调优实战
本专题系统讲解 Golang 应用的性能分析与调优方法,重点覆盖 pprof 的使用方式,包括 CPU、内存、阻塞与 goroutine 分析,火焰图解读,常见性能瓶颈定位思路,以及在真实项目中进行针对性优化的实践技巧。通过案例讲解,帮助开发者掌握 用数据驱动的方式持续提升 Go 程序性能与稳定性。
9
2026.01.22
热门下载
相关下载
精品课程
相关推荐
/
热门推荐
/
最新课程








