Skip to content

Commit db8910f

Browse files
committed
initial commit
0 parents  commit db8910f

File tree

10 files changed

+369
-0
lines changed

10 files changed

+369
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.vs
2+
/ipch
3+
/*.VC.db
4+
/*.VC.VC.opendb
5+
*.vcxproj.user
6+
Debug
7+
Release

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Christopher Gurnee
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SetScreenResolution #
2+
3+
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:
4+
5+
SetScreenResolution 1920 1080
6+
7+
8+
## Warning ##
9+
10+
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.
11+
12+
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.
13+
14+
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.
15+
16+
Please refer to the [LICENSE.txt](LICENSE.txt) file for additional details.

SetScreenResolution.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SetScreenResolution", "SetScreenResolution\SetScreenResolution.vcxproj", "{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C2474DEB-FC2C-484B-A6CA-3F826160BE13}"
9+
ProjectSection(SolutionItems) = preProject
10+
LICENSE.txt = LICENSE.txt
11+
README.md = README.md
12+
EndProjectSection
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|x64 = Debug|x64
17+
Debug|x86 = Debug|x86
18+
Release|x64 = Release|x64
19+
Release|x86 = Release|x86
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x64.ActiveCfg = Debug|x64
23+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x64.Build.0 = Debug|x64
24+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x86.ActiveCfg = Debug|Win32
25+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Debug|x86.Build.0 = Debug|Win32
26+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x64.ActiveCfg = Release|x64
27+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x64.Build.0 = Release|x64
28+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x86.ActiveCfg = Release|Win32
29+
{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}.Release|x86.Build.0 = Release|Win32
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
EndGlobal
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SetScreenResolution - a Windows utility to change the screen resolution via the command line
2+
// Copyright (C) 2016 Christopher Gurnee
3+
//
4+
// Please refer to LICENSE.txt for details about distribution and modification
5+
6+
#include "stdafx.h"
7+
8+
int wmain(int argc, wchar_t* argv[])
9+
{
10+
std::ios_base::sync_with_stdio(false);
11+
12+
DEVMODE dm;
13+
dm.dmSize = sizeof dm;
14+
dm.dmDriverExtra = 0;
15+
16+
try {
17+
if (argc != 3)
18+
throw std::runtime_error("wrong number of arguments - must specify two: width and height (in pixels)");
19+
20+
if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm) == 0)
21+
throw std::runtime_error("can't retrieve current display settings");
22+
23+
DWORD new_width = boost::lexical_cast<DWORD>(argv[1]),
24+
new_height = boost::lexical_cast<DWORD>(argv[2]);
25+
if (dm.dmPelsWidth == new_width && dm.dmPelsHeight == new_height) {
26+
std::wcout << L"The display is already set to " << new_width << L"x" << new_height << L".\n";
27+
return 0;
28+
}
29+
30+
dm.dmPelsWidth = new_width;
31+
dm.dmPelsHeight = new_height;
32+
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
33+
34+
if (ChangeDisplaySettings(&dm, CDS_TEST) != DISP_CHANGE_SUCCESSFUL)
35+
throw std::runtime_error("unsupported resolution");
36+
37+
switch (ChangeDisplaySettings(&dm, CDS_UPDATEREGISTRY)) {
38+
case DISP_CHANGE_SUCCESSFUL:
39+
break;
40+
case DISP_CHANGE_RESTART:
41+
std::wcout << L"Please restart your computer to complete this change.\n";
42+
break;
43+
default:
44+
throw std::runtime_error("resolution change failed");
45+
}
46+
47+
} catch (const std::exception& e) {
48+
std::wcerr << L"Error: " << e.what() << L"\nPress any key to exit...";
49+
_getch();
50+
return 1;
51+
}
52+
53+
std::wcout << L"Done.\n";
54+
}
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{BDD7DA11-7288-4430-8B87-79AC6B5B6FB9}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>SetScreenResolution</RootNamespace>
25+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v140</PlatformToolset>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v140</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v140</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v140</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<LinkIncremental>true</LinkIncremental>
74+
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
75+
<IntDir>$(Platform)\$(Configuration)\</IntDir>
76+
</PropertyGroup>
77+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
78+
<LinkIncremental>true</LinkIncremental>
79+
</PropertyGroup>
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
81+
<LinkIncremental>false</LinkIncremental>
82+
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
83+
<IntDir>$(Platform)\$(Configuration)\</IntDir>
84+
</PropertyGroup>
85+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
86+
<LinkIncremental>false</LinkIncremental>
87+
</PropertyGroup>
88+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
89+
<ClCompile>
90+
<PrecompiledHeader>Use</PrecompiledHeader>
91+
<WarningLevel>Level3</WarningLevel>
92+
<Optimization>Disabled</Optimization>
93+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
94+
<SDLCheck>true</SDLCheck>
95+
<AdditionalIncludeDirectories>D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
96+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
97+
</ClCompile>
98+
<Link>
99+
<SubSystem>Console</SubSystem>
100+
<GenerateDebugInformation>true</GenerateDebugInformation>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104+
<ClCompile>
105+
<PrecompiledHeader>Use</PrecompiledHeader>
106+
<WarningLevel>Level3</WarningLevel>
107+
<Optimization>Disabled</Optimization>
108+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
109+
<SDLCheck>true</SDLCheck>
110+
<AdditionalIncludeDirectories>D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
111+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
112+
</ClCompile>
113+
<Link>
114+
<SubSystem>Console</SubSystem>
115+
<GenerateDebugInformation>true</GenerateDebugInformation>
116+
</Link>
117+
</ItemDefinitionGroup>
118+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
119+
<ClCompile>
120+
<WarningLevel>Level3</WarningLevel>
121+
<PrecompiledHeader>Use</PrecompiledHeader>
122+
<Optimization>MaxSpeed</Optimization>
123+
<FunctionLevelLinking>true</FunctionLevelLinking>
124+
<IntrinsicFunctions>true</IntrinsicFunctions>
125+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
126+
<SDLCheck>true</SDLCheck>
127+
<AdditionalIncludeDirectories>D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
128+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
129+
</ClCompile>
130+
<Link>
131+
<SubSystem>Console</SubSystem>
132+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
133+
<OptimizeReferences>true</OptimizeReferences>
134+
<GenerateDebugInformation>true</GenerateDebugInformation>
135+
</Link>
136+
</ItemDefinitionGroup>
137+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
138+
<ClCompile>
139+
<WarningLevel>Level3</WarningLevel>
140+
<PrecompiledHeader>Use</PrecompiledHeader>
141+
<Optimization>MaxSpeed</Optimization>
142+
<FunctionLevelLinking>true</FunctionLevelLinking>
143+
<IntrinsicFunctions>true</IntrinsicFunctions>
144+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
145+
<SDLCheck>true</SDLCheck>
146+
<AdditionalIncludeDirectories>D:\boost\boost_1_61_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
147+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
148+
</ClCompile>
149+
<Link>
150+
<SubSystem>Console</SubSystem>
151+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
152+
<OptimizeReferences>true</OptimizeReferences>
153+
<GenerateDebugInformation>true</GenerateDebugInformation>
154+
</Link>
155+
</ItemDefinitionGroup>
156+
<ItemGroup>
157+
<ClInclude Include="stdafx.h" />
158+
<ClInclude Include="targetver.h" />
159+
</ItemGroup>
160+
<ItemGroup>
161+
<ClCompile Include="SetScreenResolution.cpp" />
162+
<ClCompile Include="stdafx.cpp">
163+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
164+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
165+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
166+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
167+
</ClCompile>
168+
</ItemGroup>
169+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
170+
<ImportGroup Label="ExtensionTargets">
171+
</ImportGroup>
172+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="stdafx.h">
19+
<Filter>Header Files</Filter>
20+
</ClInclude>
21+
<ClInclude Include="targetver.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
</ItemGroup>
25+
<ItemGroup>
26+
<ClCompile Include="stdafx.cpp">
27+
<Filter>Source Files</Filter>
28+
</ClCompile>
29+
<ClCompile Include="SetScreenResolution.cpp">
30+
<Filter>Source Files</Filter>
31+
</ClCompile>
32+
</ItemGroup>
33+
</Project>

SetScreenResolution/stdafx.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// stdafx.cpp : source file that includes just the standard includes
2+
// SetScreenResolution.pch will be the pre-compiled header
3+
// stdafx.obj will contain the pre-compiled type information
4+
5+
#include "stdafx.h"
6+
7+
// TODO: reference any additional headers you need in STDAFX.H
8+
// and not in this file

SetScreenResolution/stdafx.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// stdafx.h : include file for standard system include files,
2+
// or project specific include files that are used frequently, but
3+
// are changed infrequently
4+
//
5+
6+
#pragma once
7+
8+
#define WIN32_LEAN_AND_MEAN
9+
#include "targetver.h"
10+
#include <windows.h>
11+
#include <conio.h>
12+
13+
#include <iostream>
14+
#include <boost/lexical_cast.hpp>

SetScreenResolution/targetver.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
// Including SDKDDKVer.h defines the highest available Windows platform.
4+
5+
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6+
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7+
8+
// target Vista or higher
9+
#define _WIN32_WINNT 0x0600
10+
#include <SDKDDKVer.h>

0 commit comments

Comments
 (0)