Skip to content

Commit 735f781

Browse files
committed
Added setres spike
1 parent d3fd19f commit 735f781

File tree

5 files changed

+341
-0
lines changed

5 files changed

+341
-0
lines changed

spikes/winsetres/.gitignore

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
11+
[Dd]ebug/
12+
[Rr]elease/
13+
x64/
14+
build/
15+
[Bb]in/
16+
[Oo]bj/
17+
18+
# MSTest test Results
19+
[Tt]est[Rr]esult*/
20+
[Bb]uild[Ll]og.*
21+
22+
*_i.c
23+
*_p.c
24+
*.ilk
25+
*.meta
26+
*.obj
27+
*.pch
28+
*.pdb
29+
*.pgc
30+
*.pgd
31+
*.rsp
32+
*.sbr
33+
*.tlb
34+
*.tli
35+
*.tlh
36+
*.tmp
37+
*.tmp_proj
38+
*.log
39+
*.vspscc
40+
*.vssscc
41+
.builds
42+
*.pidb
43+
*.log
44+
*.scc
45+
46+
# Visual C++ cache files
47+
ipch/
48+
*.aps
49+
*.ncb
50+
*.opensdf
51+
*.sdf
52+
*.cachefile
53+
54+
# Visual Studio profiler
55+
*.psess
56+
*.vsp
57+
*.vspx
58+
59+
# Guidance Automation Toolkit
60+
*.gpState
61+
62+
# ReSharper is a .NET coding add-in
63+
_ReSharper*/
64+
*.[Rr]e[Ss]harper
65+
66+
# TeamCity is a build add-in
67+
_TeamCity*
68+
69+
# DotCover is a Code Coverage Tool
70+
*.dotCover
71+
72+
# NCrunch
73+
*.ncrunch*
74+
.*crunch*.local.xml
75+
76+
# Installshield output folder
77+
[Ee]xpress/
78+
79+
# DocProject is a documentation generator add-in
80+
DocProject/buildhelp/
81+
DocProject/Help/*.HxT
82+
DocProject/Help/*.HxC
83+
DocProject/Help/*.hhc
84+
DocProject/Help/*.hhk
85+
DocProject/Help/*.hhp
86+
DocProject/Help/Html2
87+
DocProject/Help/html
88+
89+
# Click-Once directory
90+
publish/
91+
92+
# Publish Web Output
93+
*.Publish.xml
94+
*.pubxml
95+
96+
# NuGet Packages Directory
97+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
98+
#packages/
99+
100+
# Windows Azure Build Output
101+
csx
102+
*.build.csdef
103+
104+
# Windows Store app package directory
105+
AppPackages/
106+
107+
# Others
108+
sql/
109+
*.Cache
110+
ClientBin/
111+
[Ss]tyle[Cc]op.*
112+
~$*
113+
*~
114+
*.dbmdl
115+
*.[Pp]ublish.xml
116+
*.pfx
117+
*.publishsettings
118+
119+
# RIA/Silverlight projects
120+
Generated_Code/
121+
122+
# Backup & report files from converting an old project file to a newer
123+
# Visual Studio version. Backup files are not needed, because we have git ;-)
124+
_UpgradeReport_Files/
125+
Backup*/
126+
UpgradeLog*.XML
127+
UpgradeLog*.htm
128+
129+
# SQL Server files
130+
App_Data/*.mdf
131+
App_Data/*.ldf
132+
133+
# =========================
134+
# Windows detritus
135+
# =========================
136+
137+
# Windows image file caches
138+
Thumbs.db
139+
ehthumbs.db
140+
141+
# Folder config file
142+
Desktop.ini
143+
144+
# Recycle Bin used on file shares
145+
$RECYCLE.BIN/
146+
147+
# Mac crap
148+
.DS_Store

spikes/winsetres/winsetres.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.30723.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winsetres", "winsetres\winsetres.vcxproj", "{0B7A88E8-2175-4FA4-A7D9-03260EB04564}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Win32 = Debug|Win32
11+
Release|Win32 = Release|Win32
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{0B7A88E8-2175-4FA4-A7D9-03260EB04564}.Debug|Win32.ActiveCfg = Debug|Win32
15+
{0B7A88E8-2175-4FA4-A7D9-03260EB04564}.Debug|Win32.Build.0 = Debug|Win32
16+
{0B7A88E8-2175-4FA4-A7D9-03260EB04564}.Release|Win32.ActiveCfg = Release|Win32
17+
{0B7A88E8-2175-4FA4-A7D9-03260EB04564}.Release|Win32.Build.0 = Release|Win32
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A spike to test progamatically changing screen resolution
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <SDKDDKVer.h>
2+
#include <windows.h>
3+
#include <tchar.h>
4+
#include <stdio.h>
5+
6+
static SIZE getScreenResolution()
7+
{
8+
int index = 0;
9+
DEVMODE dm;
10+
ZeroMemory(&dm, sizeof(dm));
11+
dm.dmSize = sizeof(dm);
12+
13+
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
14+
{
15+
return { dm.dmPelsWidth, dm.dmPelsHeight };
16+
}
17+
18+
return { 0, 0 };
19+
20+
}
21+
22+
static BOOL setScreenResolution(SIZE res)
23+
{
24+
const LONG width = res.cx;
25+
const LONG height = res.cy;
26+
27+
int index = 0;
28+
DEVMODE dm;
29+
ZeroMemory(&dm, sizeof(dm));
30+
dm.dmSize = sizeof(dm);
31+
32+
while (0 != EnumDisplaySettings(NULL, index++, &dm))
33+
{
34+
if (dm.dmPelsWidth == width && dm.dmPelsHeight == height)
35+
{
36+
DEVMODE dmCurrent;
37+
ZeroMemory(&dmCurrent, sizeof(dmCurrent));
38+
dmCurrent.dmSize = sizeof(dmCurrent);
39+
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmCurrent))
40+
{
41+
// Note: ChangeDisplaySettings has no effect if new is same as current
42+
dmCurrent.dmPelsWidth = width;
43+
dmCurrent.dmPelsHeight = height;
44+
long lRet = ChangeDisplaySettings(&dmCurrent, 0);
45+
if (DISP_CHANGE_SUCCESSFUL == lRet)
46+
{
47+
return TRUE;
48+
}
49+
if (DISP_CHANGE_RESTART == lRet)
50+
{
51+
printf("Reset required\r\n");
52+
return TRUE;
53+
}
54+
}
55+
}
56+
}
57+
58+
return FALSE;
59+
}
60+
61+
62+
int _tmain(int argc, _TCHAR* argv[])
63+
{
64+
static wchar_t buf[100];
65+
66+
SIZE res = getScreenResolution();
67+
swprintf_s(buf, _countof(buf), L"%u %u\r\n", res.cx, res.cy);
68+
wprintf(buf);
69+
70+
if (argc > 2)
71+
{
72+
SIZE newRes = { _wtoi(argv[1]), _wtoi(argv[2]) };
73+
BOOL r = setScreenResolution(newRes);
74+
printf((r) ? "Set OK\r\n" : "Set Failed\r\n");
75+
}
76+
77+
res = getScreenResolution();
78+
swprintf_s(buf, _countof(buf), L"%u %u\r\n", res.cx, res.cy);
79+
wprintf(buf);
80+
81+
return 0;
82+
}
83+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.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+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{0B7A88E8-2175-4FA4-A7D9-03260EB04564}</ProjectGuid>
15+
<Keyword>Win32Proj</Keyword>
16+
<RootNamespace>winsetres</RootNamespace>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20+
<ConfigurationType>Application</ConfigurationType>
21+
<UseDebugLibraries>true</UseDebugLibraries>
22+
<PlatformToolset>v120</PlatformToolset>
23+
<CharacterSet>Unicode</CharacterSet>
24+
</PropertyGroup>
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26+
<ConfigurationType>Application</ConfigurationType>
27+
<UseDebugLibraries>false</UseDebugLibraries>
28+
<PlatformToolset>v120</PlatformToolset>
29+
<WholeProgramOptimization>true</WholeProgramOptimization>
30+
<CharacterSet>Unicode</CharacterSet>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33+
<ImportGroup Label="ExtensionSettings">
34+
</ImportGroup>
35+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37+
</ImportGroup>
38+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
39+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40+
</ImportGroup>
41+
<PropertyGroup Label="UserMacros" />
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
43+
<LinkIncremental>true</LinkIncremental>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46+
<LinkIncremental>false</LinkIncremental>
47+
</PropertyGroup>
48+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
49+
<ClCompile>
50+
<PrecompiledHeader>
51+
</PrecompiledHeader>
52+
<WarningLevel>Level3</WarningLevel>
53+
<Optimization>Disabled</Optimization>
54+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
55+
</ClCompile>
56+
<Link>
57+
<SubSystem>Console</SubSystem>
58+
<GenerateDebugInformation>true</GenerateDebugInformation>
59+
</Link>
60+
</ItemDefinitionGroup>
61+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62+
<ClCompile>
63+
<WarningLevel>Level3</WarningLevel>
64+
<PrecompiledHeader>
65+
</PrecompiledHeader>
66+
<Optimization>MaxSpeed</Optimization>
67+
<FunctionLevelLinking>true</FunctionLevelLinking>
68+
<IntrinsicFunctions>true</IntrinsicFunctions>
69+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
70+
</ClCompile>
71+
<Link>
72+
<SubSystem>Console</SubSystem>
73+
<GenerateDebugInformation>true</GenerateDebugInformation>
74+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
75+
<OptimizeReferences>true</OptimizeReferences>
76+
</Link>
77+
</ItemDefinitionGroup>
78+
<ItemGroup>
79+
<Text Include="ReadMe.txt" />
80+
</ItemGroup>
81+
<ItemGroup>
82+
<ClCompile Include="winsetres.cpp" />
83+
</ItemGroup>
84+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
85+
<ImportGroup Label="ExtensionTargets">
86+
</ImportGroup>
87+
</Project>

0 commit comments

Comments
 (0)