tool: update code

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-09-23 14:24:55 +08:00
parent 684ebc3fa3
commit 95449f140f
3 changed files with 28 additions and 14 deletions

View File

@ -20,7 +20,7 @@ string(REGEX REPLACE "[-|/]GR" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
#string(REGEX REPLACE "[-|/]EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "[-|/]W[0|1|2|3|4]" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REGEX REPLACE "[-|/]Ob[0|1|2|3]" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(APPEND CMAKE_RC_FLAGS " /c65001 /nologo ")
string(APPEND CMAKE_RC_FLAGS " /c65001 /DWIN32 /nologo ")
add_executable(${PROJECT_NAME})
@ -32,14 +32,15 @@ set(_WIN32_WINNT_WIN10 0x0A00)
set(NTDDI_WIN10_CO 0x0A00000B)
target_compile_definitions(${PROJECT_NAME} PRIVATE
_CRT_NON_CONFORMING_SWPRINTFS _CRT_SECURE_NO_WARNINGS
_ENABLE_EXTENDED_ALIGNED_STORAGE NOMINMAX UNICODE
_UNICODE WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN
_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_WARNINGS
_CRT_NONSTDC_NO_DEPRECATE _ENABLE_EXTENDED_ALIGNED_STORAGE
NOMINMAX UNICODE _UNICODE WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN
WINVER=${_WIN32_WINNT_WIN10} _WIN32_WINNT=${_WIN32_WINNT_WIN10}
_WIN32_IE=${_WIN32_WINNT_WIN10} NTDDI_VERSION=${NTDDI_WIN10_CO}
)
target_compile_options(${PROJECT_NAME} PRIVATE
/await:strict /bigobj /d2FH4 /FS /GR- /MP /permissive- /utf-8 /W4 /WX /ZH:SHA_256
/await:strict /bigobj /d2FH4 /EHsc /FS /GR- /MP /permissive- /utf-8 /W4 /WX /ZH:SHA_256
/Zc:char8_t,__cplusplus,externC,externConstexpr,hiddenFriend,lambda,preprocessor,referenceBinding,rvalueCast,strictStrings,ternary,throwingNew,trigraphs
$<$<CONFIG:Debug>:/JMC>
$<$<NOT:$<CONFIG:Debug>>:/guard:cf /guard:ehcont /GA /GT /Gw /Gy /Ob3 /Oi /Oy /QIntel-jcc-erratum /Qspectre-load /Zc:inline>

View File

@ -71,7 +71,7 @@
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor, System</dpiAwareness>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<printerDriverIsolation xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">True</printerDriverIsolation>
<disableWindowFiltering xmlns="http://schemas.microsoft.com/SMI/2011/WindowsSettings">True</disableWindowFiltering>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">True</longPathAware>

View File

@ -217,8 +217,7 @@ void HiDPI::Initialize()
std::wcerr << L"Failed to retrieve the handle of the SHCORE.DLL." << std::endl;
}
const HINSTANCE instance = GetModuleHandleW(nullptr);
if (instance) {
if (const HINSTANCE instance = GetModuleHandleW(nullptr)) {
WNDCLASSEXW wcex;
SecureZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(wcex);
@ -270,9 +269,8 @@ void HiDPI::Cleanup()
[[nodiscard]] static inline UINT GetCurrentDPIForPrimaryScreen()
{
HiDPI::Initialize();
if (HiDPI::GetDpiForMonitorPtr) {
const HMONITOR hMonitor = MonitorFromWindow(HiDPI::FakeWindow, MONITOR_DEFAULTTOPRIMARY);
if (hMonitor) {
if (const HMONITOR hMonitor = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY)) {
if (HiDPI::GetDpiForMonitorPtr) {
UINT dpiX = 0, dpiY = 0;
const HRESULT hr = HiDPI::GetDpiForMonitorPtr(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
if (SUCCEEDED(hr) && (dpiX > 0) && (dpiY > 0)) {
@ -280,12 +278,27 @@ void HiDPI::Cleanup()
} else {
std::wcerr << L"GetDpiForMonitor() failed." << std::endl;
}
} else {
std::wcerr << L"Failed to retrieve the current monitor." << std::endl;
}
MONITORINFOEXW monitorInfo;
SecureZeroMemory(&monitorInfo, sizeof(monitorInfo));
monitorInfo.cbSize = sizeof(monitorInfo);
GetMonitorInfoW(hMonitor, &monitorInfo);
if (const HDC hdc = CreateDCW(monitorInfo.szDevice, monitorInfo.szDevice, nullptr, nullptr)) {
const int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
const int dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
DeleteDC(hdc);
if ((dpiX > 0) && (dpiY > 0)) {
return dpiX;
} else {
std::wcerr << L"Failed to retrieve the primary screen's DPI." << std::endl;
}
} else {
std::wcerr << L"Failed to create DC for the primary monitor." << std::endl;
}
} else {
std::wcerr << L"Failed to retrieve the primary monitor." << std::endl;
}
const HDC hdc = GetDC(nullptr);
if (hdc) {
if (const HDC hdc = GetDC(nullptr)) {
const int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
const int dpiY = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(nullptr, hdc);