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">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
69
src/main.cpp
69
src/main.cpp
@@ -50,6 +50,40 @@ float timer_ink_touch = 0;
|
|||||||
float timer_ink_pen = 0;
|
float timer_ink_pen = 0;
|
||||||
bool sandboxed = false;
|
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.
|
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
|
||||||
std::string GetLastErrorAsString()
|
std::string GetLastErrorAsString()
|
||||||
{
|
{
|
||||||
@@ -618,9 +652,10 @@ LRESULT CALLBACK splash_proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lPara
|
|||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
{
|
||||||
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
|
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
|
||||||
auto x = unsigned{};
|
auto x = unsigned{ 96 };
|
||||||
auto y = unsigned{};
|
auto y = unsigned{ 96 };
|
||||||
GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
if (GetDpiForMonitor_fn)
|
||||||
|
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
||||||
float z = (float)x / 96.f;
|
float z = (float)x / 96.f;
|
||||||
|
|
||||||
static char base_path[MAX_PATH];
|
static char base_path[MAX_PATH];
|
||||||
@@ -691,9 +726,13 @@ int main(int argc, char** argv)
|
|||||||
WNDCLASS wc;
|
WNDCLASS wc;
|
||||||
PIXELFORMATDESCRIPTOR pfd;
|
PIXELFORMATDESCRIPTOR pfd;
|
||||||
|
|
||||||
SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
|
|
||||||
|
|
||||||
App::I.initLog();
|
App::I.initLog();
|
||||||
|
|
||||||
|
init_shcore_API();
|
||||||
|
|
||||||
|
if(SetProcessDpiAwareness_fn)
|
||||||
|
SetProcessDpiAwareness_fn(PROCESS_PER_MONITOR_DPI_AWARE);
|
||||||
|
|
||||||
|
|
||||||
FILE* fp_check = fopen("data\\layout.xml", "rb");
|
FILE* fp_check = fopen("data\\layout.xml", "rb");
|
||||||
if (!fp_check)
|
if (!fp_check)
|
||||||
@@ -742,9 +781,10 @@ int main(int argc, char** argv)
|
|||||||
RegisterClass(&wc);
|
RegisterClass(&wc);
|
||||||
|
|
||||||
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
|
auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY);
|
||||||
auto x = unsigned{};
|
auto x = unsigned{96};
|
||||||
auto y = unsigned{};
|
auto y = unsigned{96};
|
||||||
GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
if (GetDpiForMonitor_fn)
|
||||||
|
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
||||||
App::I.zoom *= (float)x / 96.f;
|
App::I.zoom *= (float)x / 96.f;
|
||||||
|
|
||||||
int show_cmd = SW_NORMAL;
|
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);
|
UINT32 pointerId = GET_POINTERID_WPARAM(wp);
|
||||||
POINTER_INPUT_TYPE pointerType = PT_POINTER;
|
POINTER_INPUT_TYPE pointerType = PT_POINTER;
|
||||||
|
|
||||||
|
if(!GetPointerInfo_fn)
|
||||||
|
break;
|
||||||
|
|
||||||
// Retrieve common pointer information
|
// Retrieve common pointer information
|
||||||
if (!GetPointerInfo(pointerId, &pointerInfo))
|
if (!GetPointerInfo_fn(pointerId, &pointerInfo))
|
||||||
{
|
{
|
||||||
// failure, call GetLastError()
|
// failure, call GetLastError()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// success, process pointerInfo
|
// success, process pointerInfo
|
||||||
if (!GetPointerType(pointerId, &pointerType))
|
if (!GetPointerType_fn(pointerId, &pointerType))
|
||||||
{
|
{
|
||||||
// failure, call GetLastError()
|
// failure, call GetLastError()
|
||||||
// set PT_POINTER to fall to default case below
|
// 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:
|
case PT_TOUCH:
|
||||||
// Retrieve touch information
|
// Retrieve touch information
|
||||||
if (!GetPointerTouchInfo(pointerId, &touchInfo))
|
if (!GetPointerTouchInfo_fn(pointerId, &touchInfo))
|
||||||
{
|
{
|
||||||
// failure, call GetLastError()
|
// failure, call GetLastError()
|
||||||
}
|
}
|
||||||
@@ -1382,7 +1425,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
|||||||
break;
|
break;
|
||||||
case PT_PEN:
|
case PT_PEN:
|
||||||
// Retrieve pen information
|
// Retrieve pen information
|
||||||
if (!GetPointerPenInfo(pointerId, &penInfo))
|
if (!GetPointerPenInfo_fn(pointerId, &penInfo))
|
||||||
{
|
{
|
||||||
// failure, call GetLastError()
|
// failure, call GetLastError()
|
||||||
}
|
}
|
||||||
@@ -1399,7 +1442,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!GetPointerInfo(pointerId, &pointerInfo))
|
if (!GetPointerInfo_fn(pointerId, &pointerInfo))
|
||||||
{
|
{
|
||||||
// failure.
|
// failure.
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,6 @@
|
|||||||
#pragma comment(lib, "glew32.lib")
|
#pragma comment(lib, "glew32.lib")
|
||||||
#pragma comment(lib, "wbemuuid.lib")
|
#pragma comment(lib, "wbemuuid.lib")
|
||||||
#pragma comment(lib, "Shlwapi.lib")
|
#pragma comment(lib, "Shlwapi.lib")
|
||||||
#pragma comment(lib, "Shcore.lib")
|
//#pragma comment(lib, "Shcore.lib")
|
||||||
#pragma comment(lib, "openvr_api.lib")
|
#pragma comment(lib, "openvr_api.lib")
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|||||||
Reference in New Issue
Block a user