win32_window.c: fix string allocations

This commit is contained in:
arturoc 2013-07-10 13:58:23 +02:00
parent bfdddec67c
commit af115856d4

View File

@ -33,7 +33,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h> #include <malloc.h>
#include <windowsx.h> #include <windowsx.h>
#include <windows.h> #include <Shellapi.h>
#define _GLFW_KEY_INVALID -2 #define _GLFW_KEY_INVALID -2
@ -719,41 +719,32 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_DROPFILES: case WM_DROPFILES:
{ {
// DragQueryFile() takes a LPWSTR for the name so we need a TCHAR string
TCHAR szName[MAX_PATH]; TCHAR szName[MAX_PATH];
// Here we cast the wParam as a HDROP handle to pass into the next functions
HDROP hDrop = (HDROP)wParam; HDROP hDrop = (HDROP)wParam;
POINT pt; POINT pt;
DragQueryPoint(hDrop, &pt); DragQueryPoint(hDrop, &pt);
//printf("%i %i \n", pt.x, pt.y);
_glfwInputMouseMotion(window,pt.x,pt.y); // Move the mouse to the position of the drop
_glfwInputCursorMotion(window,pt.x,pt.y);
// Retrieve the names of the dropped objects
// This functions has a couple functionalities. If you pass in 0xFFFFFFFF in
// the second parameter then it returns the count of how many filers were drag
// and dropped. Otherwise, the function fills in the szName string array with
// the current file being queried.
int count = DragQueryFile(hDrop, 0xFFFFFFFF, szName, MAX_PATH); int count = DragQueryFile(hDrop, 0xFFFFFFFF, szName, MAX_PATH);
char s[MAX_PATH*count];
wchar_t * s; memset(s,0,sizeof(s));
// Here we go through all the files that were drag and dropped then display them int i;
for(int i = 0; i < count; i++) for(i = 0; i < count; i++)
{ {
// Grab the name of the file associated with index "i" in the list of files dropped.
// Be sure you know that the name is attached to the FULL path of the file.
DragQueryFile(hDrop, i, szName, MAX_PATH); DragQueryFile(hDrop, i, szName, MAX_PATH);
char* utf8str = _glfwCreateUTF8FromWideString((const wchar_t*)szName)
wcscat(s, (const wchar_t*)szName); strcat(s, utf8str);
wcscat(s, (const wchar_t*)"\n"); strcat(s, "\n");
free(utf8str);
} }
free(_glfw.win32.dropString); free(_glfw.win32.dropString);
char * str = _glfwCreateUTF8FromWideString(s); _glfw.win32.dropString = strdup(s);
free(s);
_glfwInputDrop(window,_glfw.win32.dropString); _glfwInputDrop(window,_glfw.win32.dropString);
DragFinish(hDrop); DragFinish(hDrop);
break; break;
} }
@ -875,6 +866,8 @@ static int createWindow(_GLFWwindow* window,
window); // Pass object to WM_CREATE window); // Pass object to WM_CREATE
free(wideTitle); free(wideTitle);
DragAcceptFiles(window->win32.handle, TRUE);
if (!window->win32.handle) if (!window->win32.handle)
{ {