forked from sskodje/ScreenRecorderLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cpp
More file actions
32 lines (29 loc) · 743 Bytes
/
Util.cpp
File metadata and controls
32 lines (29 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "util.h"
using _GetDpiForSystem = UINT __stdcall();
/// <summary>
/// Returns the system DPI from GetDpiForSystem() on Windows 10 v1607 or above,
/// or falls back to using GetDeviceCaps for earlier windows versions.
/// </summary>
/// <returns></returns>
UINT GetSystemDpi()
{
auto libraryModule = LoadLibraryA("User32.dll");
HRESULT hr = E_FAIL;
int dpi = 96;
if (libraryModule != nullptr)
{
auto addr = GetProcAddress(libraryModule, "GetDpiForSystem");
if (addr != nullptr)
{
auto GetDpi = reinterpret_cast<_GetDpiForSystem *>(addr);
dpi = GetDpi();
}
else {
auto dc = GetDC(nullptr);
dpi = GetDeviceCaps(dc, LOGPIXELSX);
ReleaseDC(nullptr, dc);
}
FreeLibrary(libraryModule);
}
return dpi;
}