Skip to content

Commit

Permalink
Windows Screengrab DPI fix improvements (#2)
Browse files Browse the repository at this point in the history
* Load User32 after possible return

* Removed unused setting of variable
  • Loading branch information
radarhere committed Aug 12, 2019
1 parent cacbdc6 commit d46f81a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/display.c
Expand Up @@ -332,8 +332,8 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
DWORD rop;
PyObject* buffer;
HANDLE dpiAwareness;
HMODULE user32 = LoadLibraryA("User32.dll");
Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function;
HMODULE user32;
Func_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContext_function;

if (!PyArg_ParseTuple(args, "|i", &includeLayeredWindows))
return NULL;
Expand All @@ -346,6 +346,7 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)

// added in Windows 10 (1607)
// loaded dynamically to avoid link errors
user32 = LoadLibraryA("User32.dll");
SetThreadDpiAwarenessContext_function =
(Func_SetThreadDpiAwarenessContext)
GetProcAddress(user32, "SetThreadDpiAwarenessContext");
Expand All @@ -358,7 +359,7 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
height = GetDeviceCaps(screen, VERTRES);

if (SetThreadDpiAwarenessContext_function != NULL) {
dpiAwareness = SetThreadDpiAwarenessContext_function(dpiAwareness);
SetThreadDpiAwarenessContext_function(dpiAwareness);
}

FreeLibrary(user32);
Expand Down

0 comments on commit d46f81a

Please sign in to comment.