From cf177905e506cdd21e86896e24201230aff953d9 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 10 Feb 2014 15:03:23 +0100 Subject: [PATCH] Allowed drops from less privileged processes. By default, UAC will prevent less privileged processes from sending these messages. This resolves that on Windows 7 and later. Windows Vista is still affected by this issue, as it has UAC but lacks ChangeWindowMessageFilterEx. Fixes #227. --- src/win32_init.c | 2 ++ src/win32_platform.h | 17 +++++++++++++++++ src/win32_window.c | 10 ++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/win32_init.c b/src/win32_init.c index 94190398..cc33bc38 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -96,6 +96,8 @@ static GLboolean initLibraries(void) { _glfw.win32.user32.SetProcessDPIAware = (SETPROCESSDPIAWARE_T) GetProcAddress(_glfw.win32.user32.instance, "SetProcessDPIAware"); + _glfw.win32.user32.ChangeWindowMessageFilterEx = (CHANGEWINDOWMESSAGEFILTEREX_T) + GetProcAddress(_glfw.win32.user32.instance, "ChangeWindowMessageFilterEx"); } _glfw.win32.dwmapi.instance = LoadLibrary(L"dwmapi.dll"); diff --git a/src/win32_platform.h b/src/win32_platform.h index 5f781eb0..c0395bb9 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -77,6 +77,20 @@ #ifndef WM_DWMCOMPOSITIONCHANGED #define WM_DWMCOMPOSITIONCHANGED 0x031E #endif +#ifndef WM_COPYGLOBALDATA + #define WM_COPYGLOBALDATA 0x0049 +#endif +#ifndef MSGFLT_ALLOW + #define MSGFLT_ALLOW 1 +#endif + +#if defined(__MINGW32__) +typedef struct tagCHANGEFILTERSTRUCT +{ + DWORD cbSize; + DWORD ExtStatus; +} CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT; +#endif /*__MINGW32__*/ //======================================================================== @@ -107,7 +121,9 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); // user32.dll function pointer typedefs typedef BOOL (WINAPI * SETPROCESSDPIAWARE_T)(void); +typedef BOOL (WINAPI * CHANGEWINDOWMESSAGEFILTEREX_T)(HWND,UINT,DWORD,PCHANGEFILTERSTRUCT); #define _glfw_SetProcessDPIAware _glfw.win32.user32.SetProcessDPIAware +#define _glfw_ChangeWindowMessageFilterEx _glfw.win32.user32.ChangeWindowMessageFilterEx // dwmapi.dll function pointer typedefs typedef HRESULT (WINAPI * DWMISCOMPOSITIONENABLED_T)(BOOL*); @@ -192,6 +208,7 @@ typedef struct _GLFWlibraryWin32 struct { HINSTANCE instance; SETPROCESSDPIAWARE_T SetProcessDPIAware; + CHANGEWINDOWMESSAGEFILTEREX_T ChangeWindowMessageFilterEx; } user32; // dwmapi.dll diff --git a/src/win32_window.c b/src/win32_window.c index 3a0073d3..87831d21 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -901,6 +901,16 @@ static int createWindow(_GLFWwindow* window, free(wideTitle); + if (_glfw_ChangeWindowMessageFilterEx) + { + _glfw_ChangeWindowMessageFilterEx(window->win32.handle, + WM_DROPFILES, MSGFLT_ALLOW, NULL); + _glfw_ChangeWindowMessageFilterEx(window->win32.handle, + WM_COPYDATA, MSGFLT_ALLOW, NULL); + _glfw_ChangeWindowMessageFilterEx(window->win32.handle, + WM_COPYGLOBALDATA, MSGFLT_ALLOW, NULL); + } + DragAcceptFiles(window->win32.handle, TRUE); if (!window->win32.handle)