mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
tools: monitor report info
This commit is contained in:
committed by
Andrey Nekrasov
parent
24906e6fa5
commit
8fcb76e300
113
tools/monitor_info_report/main.vcxproj
Normal file
113
tools/monitor_info_report/main.vcxproj
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="monitor-report-info.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>{6A7F9A7C-56B6-9B0D-FFA2-8110EBB8170F}</ProjectGuid>
|
||||||
|
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>main</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<OutDir>bin\</OutDir>
|
||||||
|
<IntDir>obj\Debug\</IntDir>
|
||||||
|
<TargetName>monitor_info_reportd</TargetName>
|
||||||
|
<TargetExt>.exe</TargetExt>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<OutDir>bin\</OutDir>
|
||||||
|
<IntDir>obj\Release\</IntDir>
|
||||||
|
<TargetName>monitor_info_report</TargetName>
|
||||||
|
<TargetExt>.exe</TargetExt>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
|
<DisableSpecificWarnings>4127;4275;5054;4201;4100;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||||
|
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<AdditionalIncludeDirectories>..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||||
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
|
<AdditionalOptions>/permissive- /await /Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<FullProgramDatabaseFile>true</FullProgramDatabaseFile>
|
||||||
|
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
<Lib>
|
||||||
|
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
|
||||||
|
</Lib>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level4</WarningLevel>
|
||||||
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
|
<DisableSpecificWarnings>4127;4275;5054;4201;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||||
|
<PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<AdditionalIncludeDirectories>..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
<Optimization>Full</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<MinimalRebuild>false</MinimalRebuild>
|
||||||
|
<StringPooling>true</StringPooling>
|
||||||
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
|
<AdditionalOptions>/permissive- /await /Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
</Link>
|
||||||
|
<Lib>
|
||||||
|
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
|
||||||
|
</Lib>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
106
tools/monitor_info_report/monitor-report-info.cpp
Normal file
106
tools/monitor_info_report/monitor-report-info.cpp
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#include <Windows.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ctime>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
std::wstring last_error()
|
||||||
|
{
|
||||||
|
const DWORD error_code = GetLastError();
|
||||||
|
wchar_t* error_msg;
|
||||||
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||||
|
nullptr,
|
||||||
|
error_code,
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
reinterpret_cast<LPWSTR>(&error_msg),
|
||||||
|
0,
|
||||||
|
nullptr);
|
||||||
|
std::wstring result{ error_msg };
|
||||||
|
LocalFree(error_msg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int report(std::wostream& os)
|
||||||
|
{
|
||||||
|
auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
|
||||||
|
std::wostream& os = *(std::wostream*)prm;
|
||||||
|
MONITORINFOEX mi;
|
||||||
|
mi.cbSize = sizeof(mi);
|
||||||
|
if (GetMonitorInfo(monitor, &mi))
|
||||||
|
{
|
||||||
|
os << "GetMonitorInfo OK\n";
|
||||||
|
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };
|
||||||
|
|
||||||
|
if (EnumDisplayDevices(mi.szDevice, 0, &displayDevice, 1))
|
||||||
|
{
|
||||||
|
if (displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)
|
||||||
|
{
|
||||||
|
os << "EnumDisplayDevices OK[MIRRORING_DRIVER]: \n"
|
||||||
|
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
|
||||||
|
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
|
||||||
|
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
|
||||||
|
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << "EnumDisplayDevices OK:\n"
|
||||||
|
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
|
||||||
|
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
|
||||||
|
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
|
||||||
|
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << "EnumDisplayDevices FAILED: " << last_error() << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << "GetMonitorInfo FAILED: " << last_error() << '\n';
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&os))
|
||||||
|
{
|
||||||
|
os << "EnumDisplayMonitors OK\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << "EnumDisplayMonitors FAILED: " << last_error() << '\n';
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm* timeinfo;
|
||||||
|
char buffer[1024];
|
||||||
|
|
||||||
|
time(&rawtime);
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
|
||||||
|
strftime(buffer, sizeof(buffer), "monitor-info-report-%d-%m-%Y-%H-%M-%S.txt", timeinfo);
|
||||||
|
std::string str(buffer);
|
||||||
|
|
||||||
|
std::wofstream of{ str };
|
||||||
|
std::wostringstream oss;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
oss << "GetSystemMetrics = " << GetSystemMetrics(SM_CMONITORS) << '\n';
|
||||||
|
report(oss);
|
||||||
|
}
|
||||||
|
catch (std::exception& ex)
|
||||||
|
{
|
||||||
|
oss << "exception: " << ex.what() << '\n';
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
oss << "unknown exception: " << last_error() << '\n';
|
||||||
|
}
|
||||||
|
of << oss.str();
|
||||||
|
std::wcout << oss.str() << '\n';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
20
tools/monitor_info_report/monitor_info_report.sln
Normal file
20
tools/monitor_info_report/monitor_info_report.sln
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "main", "main.vcxproj", "{6A7F9A7C-56B6-9B0D-FFA2-8110EBB8170F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{6A7F9A7C-56B6-9B0D-FFA2-8110EBB8170F}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{6A7F9A7C-56B6-9B0D-FFA2-8110EBB8170F}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{6A7F9A7C-56B6-9B0D-FFA2-8110EBB8170F}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{6A7F9A7C-56B6-9B0D-FFA2-8110EBB8170F}.Release|x64.Build.0 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user