Created
October 19, 2018 12:51
-
-
Save afvanwoudenberg/1237952341ddbb4823d13d2191aebfaa to your computer and use it in GitHub Desktop.
Small program to change the screen resolution from the windows command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setres.cpp | |
// Aswin van Woudenberg | |
#include <iostream> | |
#include <windows.h> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
int w; | |
int h; | |
int d; | |
DEVMODE sDevMode; | |
LONG rVal; | |
if (argc!=4) { | |
cout << "Usage: setres <width> <height> <depth>" << endl; | |
return 1; | |
} | |
w = atoi(argv[1]); | |
h = atoi(argv[2]); | |
d = atoi(argv[3]); | |
if (!w || !h || !d) { | |
cout << "Invalid argument" << endl; | |
return 1; | |
} | |
ZeroMemory(&sDevMode, sizeof(DEVMODE)); | |
sDevMode.dmSize = sizeof(DEVMODE); | |
sDevMode.dmPelsWidth = w; | |
sDevMode.dmFields |= DM_PELSWIDTH; | |
sDevMode.dmPelsHeight = h; | |
sDevMode.dmFields |= DM_PELSHEIGHT; | |
sDevMode.dmBitsPerPel = d; | |
sDevMode.dmFields |= DM_BITSPERPEL; | |
rVal = ChangeDisplaySettings(&sDevMode, CDS_UPDATEREGISTRY); | |
switch (rVal) | |
{ | |
case DISP_CHANGE_SUCCESSFUL: | |
rVal = SendMessage(HWND_BROADCAST, WM_DISPLAYCHANGE, SPI_SETNONCLIENTMETRICS, NULL); | |
return 0; | |
case DISP_CHANGE_RESTART: | |
cout << "The computer must be restarted in order for the graphics mode to work." << endl; | |
return 0; | |
case DISP_CHANGE_BADFLAGS: | |
cout << "An invalid set of flags was passed in." << endl; | |
return 1; | |
case DISP_CHANGE_FAILED: | |
cout << "The display driver failed the specified graphics mode." << endl; | |
return 1; | |
case DISP_CHANGE_BADMODE: | |
cout << "The graphics mode is not supported." << endl; | |
return 1; | |
case DISP_CHANGE_NOTUPDATED: | |
cout << "Unable to write settings to the registry." << endl; | |
return 0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment