From 72003bf1476eb9175942c8ce3a5139143844c341 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 24 May 2019 17:55:06 +0200 Subject: [PATCH] dynamically load win8+ functions for compatibility to win7 --- PanoPainter.vcxproj | 2 +- src/main.cpp | 69 ++++++++++++++++++++++++++++++++++++--------- src/pch.cpp | 2 +- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/PanoPainter.vcxproj b/PanoPainter.vcxproj index 0a287ac..52b7b19 100644 --- a/PanoPainter.vcxproj +++ b/PanoPainter.vcxproj @@ -48,7 +48,7 @@ Application false - v140 + v142 true Unicode diff --git a/src/main.cpp b/src/main.cpp index d5fc52d..f15811b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,6 +50,40 @@ float timer_ink_touch = 0; float timer_ink_pen = 0; bool sandboxed = false; +HRESULT(*GetDpiForMonitor_fn)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY); +HRESULT(*SetProcessDpiAwareness_fn)(PROCESS_DPI_AWARENESS value); +void init_shcore_API() +{ + HMODULE dll = LoadLibrary(L"Shcore.dll"); + if (!dll) + { + LOG("cannot load Shcore.dll"); + return; + } + LOG("loaded Shcore.dll"); + GetDpiForMonitor_fn = (decltype(GetDpiForMonitor_fn))GetProcAddress(dll, "GetDpiForMonitor"); + SetProcessDpiAwareness_fn = (decltype(SetProcessDpiAwareness_fn))GetProcAddress(dll, "SetProcessDpiAwareness"); +} + +BOOL(*GetPointerInfo_fn)(UINT32 pointerId, POINTER_INFO* pointerInfo); +BOOL(*GetPointerType_fn)(UINT32 pointerId, POINTER_INPUT_TYPE* pointerType); +BOOL(*GetPointerTouchInfo_fn)(UINT32 pointerId, POINTER_TOUCH_INFO* touchInfo); +BOOL(*GetPointerPenInfo_fn)(UINT32 pointerId, POINTER_PEN_INFO* penInfo); +void init_ink_API() +{ + HMODULE dll = LoadLibrary(L"User32.lib"); + if (!dll) + { + LOG("cannot load User32.lib"); + return; + } + LOG("loaded User32.lib"); + GetPointerInfo_fn = (decltype(GetPointerInfo_fn))GetProcAddress(dll, "GetPointerInfo"); + GetPointerType_fn = (decltype(GetPointerType_fn))GetProcAddress(dll, "GetPointerType"); + GetPointerTouchInfo_fn = (decltype(GetPointerTouchInfo_fn))GetProcAddress(dll, "GetPointerTouchInfo"); + GetPointerPenInfo_fn = (decltype(GetPointerPenInfo_fn))GetProcAddress(dll, "GetPointerPenInfo"); +} + //Returns the last Win32 error, in string format. Returns an empty string if there is no error. std::string GetLastErrorAsString() { @@ -618,9 +652,10 @@ LRESULT CALLBACK splash_proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lPara case WM_INITDIALOG: { auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY); - auto x = unsigned{}; - auto y = unsigned{}; - GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); + auto x = unsigned{ 96 }; + auto y = unsigned{ 96 }; + if (GetDpiForMonitor_fn) + GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y); float z = (float)x / 96.f; static char base_path[MAX_PATH]; @@ -691,9 +726,13 @@ int main(int argc, char** argv) WNDCLASS wc; PIXELFORMATDESCRIPTOR pfd; - SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); - App::I.initLog(); + + init_shcore_API(); + + if(SetProcessDpiAwareness_fn) + SetProcessDpiAwareness_fn(PROCESS_PER_MONITOR_DPI_AWARE); + FILE* fp_check = fopen("data\\layout.xml", "rb"); if (!fp_check) @@ -742,9 +781,10 @@ int main(int argc, char** argv) RegisterClass(&wc); auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY); - auto x = unsigned{}; - auto y = unsigned{}; - GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); + auto x = unsigned{96}; + auto y = unsigned{96}; + if (GetDpiForMonitor_fn) + GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y); App::I.zoom *= (float)x / 96.f; int show_cmd = SW_NORMAL; @@ -1348,15 +1388,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) UINT32 pointerId = GET_POINTERID_WPARAM(wp); POINTER_INPUT_TYPE pointerType = PT_POINTER; + if(!GetPointerInfo_fn) + break; + // Retrieve common pointer information - if (!GetPointerInfo(pointerId, &pointerInfo)) + if (!GetPointerInfo_fn(pointerId, &pointerInfo)) { // failure, call GetLastError() } else { // success, process pointerInfo - if (!GetPointerType(pointerId, &pointerType)) + if (!GetPointerType_fn(pointerId, &pointerType)) { // failure, call GetLastError() // set PT_POINTER to fall to default case below @@ -1366,7 +1409,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { case PT_TOUCH: // Retrieve touch information - if (!GetPointerTouchInfo(pointerId, &touchInfo)) + if (!GetPointerTouchInfo_fn(pointerId, &touchInfo)) { // failure, call GetLastError() } @@ -1382,7 +1425,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) break; case PT_PEN: // Retrieve pen information - if (!GetPointerPenInfo(pointerId, &penInfo)) + if (!GetPointerPenInfo_fn(pointerId, &penInfo)) { // failure, call GetLastError() } @@ -1399,7 +1442,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) } break; default: - if (!GetPointerInfo(pointerId, &pointerInfo)) + if (!GetPointerInfo_fn(pointerId, &pointerInfo)) { // failure. } diff --git a/src/pch.cpp b/src/pch.cpp index dbeac75..2ad93f5 100644 --- a/src/pch.cpp +++ b/src/pch.cpp @@ -20,6 +20,6 @@ #pragma comment(lib, "glew32.lib") #pragma comment(lib, "wbemuuid.lib") #pragma comment(lib, "Shlwapi.lib") - #pragma comment(lib, "Shcore.lib") + //#pragma comment(lib, "Shcore.lib") #pragma comment(lib, "openvr_api.lib") #endif // _WIN32