From db8910f3f6c1933ce6ca3cf92452411b7bfd2bb4 Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Sun, 10 Jul 2016 08:35:32 -0400 Subject: [PATCH] initial commit --- .gitignore | 7 + LICENSE.txt | 21 +++ README.md | 16 ++ SetScreenResolution.sln | 34 ++++ SetScreenResolution/SetScreenResolution.cpp | 54 ++++++ .../SetScreenResolution.vcxproj | 172 ++++++++++++++++++ .../SetScreenResolution.vcxproj.filters | 33 ++++ SetScreenResolution/stdafx.cpp | 8 + SetScreenResolution/stdafx.h | 14 ++ SetScreenResolution/targetver.h | 10 + 10 files changed, 369 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 SetScreenResolution.sln create mode 100644 SetScreenResolution/SetScreenResolution.cpp create mode 100644 SetScreenResolution/SetScreenResolution.vcxproj create mode 100644 SetScreenResolution/SetScreenResolution.vcxproj.filters create mode 100644 SetScreenResolution/stdafx.cpp create mode 100644 SetScreenResolution/stdafx.h create mode 100644 SetScreenResolution/targetver.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0181e72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/.vs +/ipch +/*.VC.db +/*.VC.VC.opendb +*.vcxproj.user +Debug +Release diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d4b1bb5 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Christopher Gurnee + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e018640 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# SetScreenResolution # + +SetScreenResolution is a small Windows utility to change the Desktop screen resolution via the command line. For example, to set the resolution to 1080p, you would run: + + SetScreenResolution 1920 1080 + + +## Warning ## + +Driver permitting, the resolution is changed immediately and no prompt to ensure the change occurred correctly is provided. If you change the resolution to one unsupported by your system, you may have trouble changing it back. + +It is strongly recommended that you test any resolution you'd like to use via the standard Windows display settings dialog at least once before proceeding. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + +Please refer to the [LICENSE.txt](LICENSE.txt) file for additional details. diff --git a/SetScreenResolution.sln b/SetScreenResolution.sln new file mode 100644 index 0000000..9cfc73d --- /dev/null +++ b/SetScreenResolution.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SetScreenResolution", "SetScreenResolution\SetScreenResolution.vcxproj", "{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C2474DEB-FC2C-484B-A6CA-3F826160BE13}" + ProjectSection(SolutionItems) = preProject + LICENSE.txt = LICENSE.txt + README.md = README.md + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x64.ActiveCfg = Debug|x64 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x64.Build.0 = Debug|x64 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x86.ActiveCfg = Debug|Win32 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x86.Build.0 = Debug|Win32 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x64.ActiveCfg = Release|x64 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x64.Build.0 = Release|x64 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x86.ActiveCfg = Release|Win32 + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/SetScreenResolution/SetScreenResolution.cpp b/SetScreenResolution/SetScreenResolution.cpp new file mode 100644 index 0000000..8bb3e20 --- /dev/null +++ b/SetScreenResolution/SetScreenResolution.cpp @@ -0,0 +1,54 @@ +// SetScreenResolution - a Windows utility to change the screen resolution via the command line +// Copyright (C) 2016 Christopher Gurnee +// +// Please refer to LICENSE.txt for details about distribution and modification + +#include "stdafx.h" + +int wmain(int argc, wchar_t* argv[]) +{ + std::ios_base::sync_with_stdio(false); + + DEVMODE dm; + dm.dmSize = sizeof dm; + dm.dmDriverExtra = 0; + + try { + if (argc != 3) + throw std::runtime_error("wrong number of arguments - must specify two: width and height (in pixels)"); + + if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm) == 0) + throw std::runtime_error("can't retrieve current display settings"); + + DWORD new_width = boost::lexical_cast(argv[1]), + new_height = boost::lexical_cast(argv[2]); + if (dm.dmPelsWidth == new_width && dm.dmPelsHeight == new_height) { + std::wcout << L"The display is already set to " << new_width << L"x" << new_height << L".\n"; + return 0; + } + + dm.dmPelsWidth = new_width; + dm.dmPelsHeight = new_height; + dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; + + if (ChangeDisplaySettings(&dm, CDS_TEST) != DISP_CHANGE_SUCCESSFUL) + throw std::runtime_error("unsupported resolution"); + + switch (ChangeDisplaySettings(&dm, CDS_UPDATEREGISTRY)) { + case DISP_CHANGE_SUCCESSFUL: + break; + case DISP_CHANGE_RESTART: + std::wcout << L"Please restart your computer to complete this change.\n"; + break; + default: + throw std::runtime_error("resolution change failed"); + } + + } catch (const std::exception& e) { + std::wcerr << L"Error: " << e.what() << L"\nPress any key to exit..."; + _getch(); + return 1; + } + + std::wcout << L"Done.\n"; +} \ No newline at end of file diff --git a/SetScreenResolution/SetScreenResolution.vcxproj b/SetScreenResolution/SetScreenResolution.vcxproj new file mode 100644 index 0000000..20f1e2f --- /dev/null +++ b/SetScreenResolution/SetScreenResolution.vcxproj @@ -0,0 +1,172 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {BDD7DA11-7288-4430-8B87-79AC6B5B6FB9} + Win32Proj + SetScreenResolution + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + Console + true + + + + + Use + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories) + MultiThreadedDebug + + + Console + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories) + MultiThreaded + + + Console + true + true + true + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/SetScreenResolution/SetScreenResolution.vcxproj.filters b/SetScreenResolution/SetScreenResolution.vcxproj.filters new file mode 100644 index 0000000..70ad056 --- /dev/null +++ b/SetScreenResolution/SetScreenResolution.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/SetScreenResolution/stdafx.cpp b/SetScreenResolution/stdafx.cpp new file mode 100644 index 0000000..728e9fe --- /dev/null +++ b/SetScreenResolution/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// SetScreenResolution.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/SetScreenResolution/stdafx.h b/SetScreenResolution/stdafx.h new file mode 100644 index 0000000..dab00e2 --- /dev/null +++ b/SetScreenResolution/stdafx.h @@ -0,0 +1,14 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#define WIN32_LEAN_AND_MEAN +#include "targetver.h" +#include +#include + +#include +#include \ No newline at end of file diff --git a/SetScreenResolution/targetver.h b/SetScreenResolution/targetver.h new file mode 100644 index 0000000..765a6e9 --- /dev/null +++ b/SetScreenResolution/targetver.h @@ -0,0 +1,10 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +// target Vista or higher +#define _WIN32_WINNT 0x0600 +#include