-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
90 lines (79 loc) · 2.98 KB
/
main.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <Windows.h>
#include <stdio.h>
void PutDispChangeError(LONG Result)
{
// DISP_CHANGE_RESTART;
// DISP_CHANGE_SUCCESSFUL;
// DISP_CHANGE_FAILED;
// DISP_CHANGE_BADMODE;
// DISP_CHANGE_NOTUPDATED;
// DISP_CHANGE_BADFLAGS;
// DISP_CHANGE_BADPARAM;
// DISP_CHANGE_BADDUALVIEW;
switch (Result)
{
case 1: puts(" -> DISP_CHANGE_RESTART - The computer must be restarted for the graphics mode to work."); break;
case 0: puts(" -> DISP_CHANGE_SUCCESSFUL - The settings change was successful."); break;
case -1: puts(" -> DISP_CHANGE_FAILED - The display driver failed the specified graphics mode."); break;
case -2: puts(" -> DISP_CHANGE_BADMODE - The graphics mode is not supported."); break;
case -3: puts(" -> DISP_CHANGE_NOTUPDATED - Unable to write settings to the registry."); break;
case -4: puts(" -> DISP_CHANGE_BADFLAGS - An invalid set of flags was passed in."); break;
case -5: puts(" -> DISP_CHANGE_BADPARAM - An invalid parameter was passed in. This can include an invalid flag or combination of flags."); break;
case -6: puts(" -> DISP_CHANGE_BADDUALVIEW - The settings change was unsuccessful because the system is DualView capable."); break;
default:
printf("Given result does not belong to any constant: %li!\n", Result);
}
}
int main(void)
{
DEVMODEA DisplayModeA;
BOOL Result;
LONG Result2;
DWORD TempWidth;
Result = EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &DisplayModeA); // get the current settings
if (!Result)
{
printf("Getting the display settings failed: %lu (returned from GetLastError)!\n", GetLastError());
return -1;
}
else
{
puts("Getting the display settings succeeded.");
}
if (DisplayModeA.dmFields | DM_DISPLAYORIENTATION) // if the display orientation field is initialized (i still don't know if this is important or not)
{
if (DisplayModeA.dmDisplayOrientation == DMDO_DEFAULT) // depending on the orientation the appropriate new orientation will be set
{
DisplayModeA.dmDisplayOrientation = DMDO_90;
puts("The display orientation is set to the default (DMDO_DEFAULT).");
puts("It will now be changed to DMDO_90.");
}
else
{
DisplayModeA.dmDisplayOrientation = DMDO_DEFAULT;
printf("The display orientation is set to something else: %lu (default is zero).\n", DisplayModeA.dmDisplayOrientation);
puts("It will now be changed to DMDO_DEFAULT.");
}
TempWidth = DisplayModeA.dmPelsWidth;
DisplayModeA.dmPelsWidth = DisplayModeA.dmPelsHeight;
DisplayModeA.dmPelsHeight = TempWidth;
DisplayModeA.dmFields = DM_PELSHEIGHT | DM_PELSWIDTH; // if this actually is important needs to be checked
Result2 = ChangeDisplaySettingsA(&DisplayModeA, 0);
if (Result2 == DISP_CHANGE_SUCCESSFUL)
{
puts("New settings were successfully set.");
}
else
{
printf("Applying the new display settings failed: %li (returned from ChangeDisplaySettings)!\n", Result2);
PutDispChangeError(Result2);
return -2;
}
}
else
{
puts("Display orientation field was not initialized!");
return -3;
}
return 0;
}