From 01c6a9cd09905a49ff81e9ca68c2dabd67ce86fa Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 25 Jun 2018 11:02:59 +0200 Subject: [PATCH] Fix Drop file with SDL/Win32. implement it with plain win32 we have to handle both unicode and non unicode builds --- src/input.c | 13 +++++++++++++ src/win32screen.c | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/input.c b/src/input.c index 05eef473..11cf0f84 100644 --- a/src/input.c +++ b/src/input.c @@ -1014,10 +1014,23 @@ int Get_input(int sleep_time) Drop_file_name=calloc(len+1,1); if (Drop_file_name) { +#ifdef UNICODE + TCHAR LongDropFileName[MAX_PATH]; + TCHAR ShortDropFileName[MAX_PATH]; + if (DragQueryFile(hdrop, 0 , LongDropFileName ,(UINT) MAX_PATH) + && GetShortPathName(LongDropFileName, ShortDropFileName, MAX_PATH)) + { + int i; + for (i = 0; ShortDropFileName[i] != 0; i++) + Drop_file_name[i] = (char)ShortDropFileName[i]; + Drop_file_name[i] = 0; + } +#else if (DragQueryFile(hdrop,0 ,(LPTSTR) Drop_file_name ,(UINT) MAX_PATH)) { // Success } +#endif else { free(Drop_file_name); diff --git a/src/win32screen.c b/src/win32screen.c index 81cb9127..fc1eb018 100644 --- a/src/win32screen.c +++ b/src/win32screen.c @@ -166,6 +166,32 @@ static LRESULT CALLBACK Win32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP case WM_CHAR: Key_ANSI = Key_UNICODE = wParam; return 0; + case WM_DROPFILES: + { + int file_count; + HDROP hDrop = (HDROP)wParam; + + file_count = DragQueryFile(hDrop, (UINT)-1, NULL , 0); + if (file_count > 0) + { + TCHAR LongDropFileName[MAX_PATH]; + TCHAR ShortDropFileName[MAX_PATH]; + if (DragQueryFile(hDrop, 0 , LongDropFileName ,(UINT) MAX_PATH) + && GetShortPathName(LongDropFileName, ShortDropFileName, MAX_PATH)) + { + Drop_file_name = (char *)malloc(lstrlen(ShortDropFileName) + 1); + if (Drop_file_name != NULL) + { + int i; + + for (i = 0; ShortDropFileName[i] != 0; i++) + Drop_file_name[i] = (char)ShortDropFileName[i]; + Drop_file_name[i] = 0; + } + } + } + } + return 0; default: { char msg[256];