Merge pull request #471 from sergeyreznik/win32_dpi_aware

Enable DPI awareness on Windows platform
This commit is contained in:
Sascha Willems 2018-05-06 09:19:50 +02:00 committed by GitHub
commit c76a9ffd3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -761,6 +761,7 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation)
{ {
setupConsole("Vulkan validation output"); setupConsole("Vulkan validation output");
} }
setupDPIAwareness();
#endif #endif
} }
@ -1002,6 +1003,25 @@ void VulkanExampleBase::setupConsole(std::string title)
SetConsoleTitle(TEXT(title.c_str())); SetConsoleTitle(TEXT(title.c_str()));
} }
void VulkanExampleBase::setupDPIAwareness()
{
using SetProcessDpiAwarenessFunc = HRESULT(*)(PROCESS_DPI_AWARENESS);
HMODULE shCore = LoadLibraryA("Shcore.dll");
if (shCore)
{
SetProcessDpiAwarenessFunc setProcessDpiAwareness =
(SetProcessDpiAwarenessFunc)GetProcAddress(shCore, "SetProcessDpiAwareness");
if (setProcessDpiAwareness != nullptr)
{
setProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
}
FreeLibrary(shCore);
}
}
HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
{ {
this->windowInstance = hinstance; this->windowInstance = hinstance;

View file

@ -13,6 +13,7 @@
#include <windows.h> #include <windows.h>
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#include <ShellScalingAPI.h>
#elif defined(VK_USE_PLATFORM_ANDROID_KHR) #elif defined(VK_USE_PLATFORM_ANDROID_KHR)
#include <android/native_activity.h> #include <android/native_activity.h>
#include <android/asset_manager.h> #include <android/asset_manager.h>
@ -254,6 +255,7 @@ public:
#if defined(_WIN32) #if defined(_WIN32)
void setupConsole(std::string title); void setupConsole(std::string title);
void setupDPIAwareness();
HWND setupWindow(HINSTANCE hinstance, WNDPROC wndproc); HWND setupWindow(HINSTANCE hinstance, WNDPROC wndproc);
void handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#elif defined(VK_USE_PLATFORM_ANDROID_KHR) #elif defined(VK_USE_PLATFORM_ANDROID_KHR)