Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows
authorSam Lantinga <slouken@libsdl.org>
Sun, 30 Sep 2012 11:10:17 -0700
changeset 652362d0193a7a02
parent 6522 edacce9402fb
child 6524 f63436cc3fa6
Fixed bug 1593 - SDL_DROPFILE event doesn't work on Windows

Philipp Wiesemann 2012-09-30 05:56:09 PDT

I attached a patch which tries to implement the dropfile support for Microsoft
Windows. If applied SDL_DROPFILE events should be sent for single or multiple
files which are dropped on window.

The handling on Windows side is always activated (cursor will change and so on)
because there is no connection between SDL_EventState() and the window setup. I
assumed this additional overhead would be small and can be ignored.
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowswindow.c
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Sun Sep 30 01:08:48 2012 -0700
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Sun Sep 30 11:10:17 2012 -0700
     1.3 @@ -29,6 +29,10 @@
     1.4  #include "../../events/SDL_events_c.h"
     1.5  #include "../../events/SDL_touch_c.h"
     1.6  
     1.7 +/* Dropfile support */
     1.8 +#include <shellapi.h>
     1.9 +
    1.10 +
    1.11  
    1.12  
    1.13  /*#define WMMSG_DEBUG*/
    1.14 @@ -619,7 +623,29 @@
    1.15  			return 0;
    1.16  		}
    1.17  		break;
    1.18 -	}
    1.19 +
    1.20 +    case WM_DROPFILES:
    1.21 +        {
    1.22 +            UINT i;
    1.23 +            HDROP drop = (HDROP) wParam;
    1.24 +            UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
    1.25 +            for (i = 0; i < count; ++i) {
    1.26 +                UINT size = DragQueryFile(drop, i, NULL, 0) + 1;
    1.27 +                LPTSTR buffer = SDL_stack_alloc(TCHAR, size);
    1.28 +                if (buffer) {
    1.29 +                    if (DragQueryFile(drop, i, buffer, size)) {
    1.30 +                        char *file = WIN_StringToUTF8(buffer);
    1.31 +                        SDL_SendDropFile(file);
    1.32 +                        SDL_free(file);
    1.33 +                    }
    1.34 +                    SDL_stack_free(buffer);
    1.35 +                }
    1.36 +            }
    1.37 +            DragFinish(drop);
    1.38 +            return 0;
    1.39 +        }
    1.40 +        break;
    1.41 +    }
    1.42  
    1.43      /* If there's a window proc, assume it's going to handle messages */
    1.44      if (data->wndproc) {
     2.1 --- a/src/video/windows/SDL_windowswindow.c	Sun Sep 30 01:08:48 2012 -0700
     2.2 +++ b/src/video/windows/SDL_windowswindow.c	Sun Sep 30 11:10:17 2012 -0700
     2.3 @@ -29,6 +29,9 @@
     2.4  #include "SDL_windowsvideo.h"
     2.5  #include "SDL_windowswindow.h"
     2.6  
     2.7 +/* Dropfile support */
     2.8 +#include <shellapi.h>
     2.9 +
    2.10  /* This is included after SDL_windowsvideo.h, which includes windows.h */
    2.11  #include "SDL_syswm.h"
    2.12  
    2.13 @@ -185,6 +188,9 @@
    2.14          videodata->RegisterTouchWindow(hwnd, (TWF_FINETOUCH|TWF_WANTPALM));
    2.15      }
    2.16  
    2.17 +    /* Enable dropping files */
    2.18 +    DragAcceptFiles(hwnd, TRUE);
    2.19 +
    2.20      /* All done! */
    2.21      return 0;
    2.22  }