dynamically load win8+ functions for compatibility to win7
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
||||
69
src/main.cpp
69
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.
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user