-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
45 lines (41 loc) · 1.28 KB
/
main.c
File metadata and controls
45 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
LONG change_monitor_settings(int width, int height, int refresh_rate)
{
DEVMODE dm = { 0 };
dm.dmSize = sizeof(dm);
if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)) {
return DISP_CHANGE_FAILED;
}
if (dm.dmPelsWidth == width && dm.dmPelsHeight == height && dm.dmDisplayFrequency == refresh_rate) {
return DISP_CHANGE_SUCCESSFUL; // 已经是目标设置
}
dm.dmPelsWidth = width;
dm.dmPelsHeight = height;
dm.dmDisplayFrequency = refresh_rate;
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
return ChangeDisplaySettings(&dm, CDS_UPDATEREGISTRY);
}
void print_help()
{
printf(
"rlsw.exe [width] [height] [refresh_rate]\neg: rlsw.exe 1920 1080 60\n");
}
int main(int argc, char** argv)
{
for (int i = 0; i < argc; i++) {
if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) {
print_help();
return 0;
}
}
if (argc != 4) {
print_help();
return 1;
}
int width = atoi(argv[1]);
int height = atoi(argv[2]);
int refresh_rate = atoi(argv[3]);
return change_monitor_settings(width, height, refresh_rate);
}