mirror of
https://github.com/LegacyUpdate/LegacyUpdate.git
synced 2025-01-22 14:12:07 -05:00
Move BecomeDPIAware() to Compat.h
This commit is contained in:
parent
83b5916f28
commit
6b1cff11b7
3 changed files with 40 additions and 39 deletions
|
@ -2,8 +2,22 @@
|
|||
#include <comdef.h>
|
||||
#include "Utils.h"
|
||||
|
||||
#ifndef PROCESS_PER_MONITOR_DPI_AWARE
|
||||
typedef int PROCESS_DPI_AWARENESS;
|
||||
#define PROCESS_PER_MONITOR_DPI_AWARE 2
|
||||
#endif
|
||||
|
||||
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
||||
typedef int DPI_AWARENESS_CONTEXT;
|
||||
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4)
|
||||
#endif
|
||||
|
||||
typedef BOOL (WINAPI *_GetProductInfo)(DWORD, DWORD, DWORD, DWORD, PDWORD);
|
||||
|
||||
typedef BOOL (WINAPI *_SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
|
||||
typedef HRESULT (WINAPI *_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
|
||||
typedef void (WINAPI *_SetProcessDPIAware)();
|
||||
|
||||
_GetProductInfo $GetProductInfo = (_GetProductInfo)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetProductInfo");
|
||||
|
||||
BOOL GetVistaProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType) {
|
||||
|
@ -14,3 +28,26 @@ BOOL GetVistaProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD d
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void BecomeDPIAware() {
|
||||
// Make the process DPI-aware... hopefully
|
||||
// Windows 10 1703+ per-monitor v2
|
||||
_SetProcessDpiAwarenessContext $SetProcessDpiAwarenessContext = (_SetProcessDpiAwarenessContext)GetProcAddress(LoadLibrary(L"user32.dll"), "SetProcessDpiAwarenessContext");
|
||||
if ($SetProcessDpiAwarenessContext) {
|
||||
$SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Windows 8.1 - 10 1607 per-monitor v1
|
||||
_SetProcessDpiAwareness $SetProcessDpiAwareness = (_SetProcessDpiAwareness)GetProcAddress(LoadLibrary(L"shcore.dll"), "SetProcessDpiAwareness");
|
||||
if ($SetProcessDpiAwareness) {
|
||||
$SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Windows Vista - 8
|
||||
_SetProcessDPIAware $SetProcessDPIAware = (_SetProcessDPIAware)GetProcAddress(LoadLibrary(L"user32.dll"), "SetProcessDPIAware");
|
||||
if ($SetProcessDPIAware) {
|
||||
$SetProcessDPIAware();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
BOOL GetVistaProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion, DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType);
|
||||
void BecomeDPIAware();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// ElevationHelper.cpp : Implementation of CElevationHelper
|
||||
#include "stdafx.h"
|
||||
#include "Compat.h"
|
||||
#include "ElevationHelper.h"
|
||||
#include "HResult.h"
|
||||
#include "Utils.h"
|
||||
|
@ -9,14 +10,13 @@ const BSTR permittedProgIDs[] = {
|
|||
L"Microsoft.Update.",
|
||||
NULL
|
||||
};
|
||||
const int permittedProgIDsMax = 1;
|
||||
|
||||
BOOL ProgIDIsPermitted(PWSTR progID) {
|
||||
if (progID == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < permittedProgIDsMax; i++) {
|
||||
for (int i = 0; permittedProgIDs[i] != NULL; i++) {
|
||||
if (wcsncmp(progID, permittedProgIDs[i], wcslen(permittedProgIDs[i])) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -42,43 +42,6 @@ STDMETHODIMP CoCreateInstanceAsAdmin(HWND hwnd, __in REFCLSID rclsid, __in REFII
|
|||
return CoGetObject(monikerName, &bindOpts, riid, ppv);
|
||||
}
|
||||
|
||||
#ifndef PROCESS_PER_MONITOR_DPI_AWARE
|
||||
typedef int PROCESS_DPI_AWARENESS;
|
||||
#define PROCESS_PER_MONITOR_DPI_AWARE 2
|
||||
#endif
|
||||
|
||||
#ifndef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
|
||||
typedef int DPI_AWARENESS_CONTEXT;
|
||||
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4)
|
||||
#endif
|
||||
|
||||
typedef BOOL (WINAPI *_SetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT value);
|
||||
typedef HRESULT (WINAPI *_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
|
||||
typedef void (WINAPI *_SetProcessDPIAware)();
|
||||
|
||||
static void BecomeDPIAware() {
|
||||
// Make the process DPI-aware... hopefully
|
||||
// Windows 10 1703+ per-monitor v2
|
||||
_SetProcessDpiAwarenessContext $SetProcessDpiAwarenessContext = (_SetProcessDpiAwarenessContext)GetProcAddress(LoadLibrary(L"user32.dll"), "SetProcessDpiAwarenessContext");
|
||||
if ($SetProcessDpiAwarenessContext) {
|
||||
$SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Windows 8.1 - 10 1607 per-monitor v1
|
||||
_SetProcessDpiAwareness $SetProcessDpiAwareness = (_SetProcessDpiAwareness)GetProcAddress(LoadLibrary(L"shcore.dll"), "SetProcessDpiAwareness");
|
||||
if ($SetProcessDpiAwareness) {
|
||||
$SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Windows Vista - 8
|
||||
_SetProcessDPIAware $SetProcessDPIAware = (_SetProcessDPIAware)GetProcAddress(LoadLibrary(L"user32.dll"), "SetProcessDPIAware");
|
||||
if ($SetProcessDPIAware) {
|
||||
$SetProcessDPIAware();
|
||||
}
|
||||
}
|
||||
|
||||
CElevationHelper::CElevationHelper() {
|
||||
BecomeDPIAware();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue