mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Initial drag and drop support.
This commit is contained in:
@@ -29,7 +29,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <Windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <Shellapi.h>
|
||||
|
||||
#define _GLFW_KEY_INVALID -2
|
||||
|
||||
@@ -747,6 +749,39 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
// TODO: Restore vsync if compositing was disabled
|
||||
break;
|
||||
}
|
||||
case WM_DROPFILES:
|
||||
{
|
||||
TCHAR szName[MAX_PATH];
|
||||
HDROP hDrop = (HDROP)wParam;
|
||||
POINT pt;
|
||||
int numFiles = DragQueryFile(hDrop, 0xFFFFFFFF, szName, MAX_PATH);
|
||||
int currentSize = 1;
|
||||
int i;
|
||||
char* utf8str;
|
||||
DragQueryPoint(hDrop, &pt);
|
||||
|
||||
// Move the mouse to the position of the drop
|
||||
_glfwInputCursorMotion(window,pt.x,pt.y);
|
||||
|
||||
memset(_glfw.win32.dropString, 0, _glfw.win32.dropStringSize);
|
||||
for(i = 0; i < numFiles; i++)
|
||||
{
|
||||
DragQueryFile(hDrop, i, szName, MAX_PATH);
|
||||
utf8str = _glfwCreateUTF8FromWideString((const wchar_t*)szName);
|
||||
currentSize += strlen(utf8str);
|
||||
if(_glfw.win32.dropStringSize < currentSize){
|
||||
_glfw.win32.dropStringSize *= 2;
|
||||
_glfw.win32.dropString = (char*)realloc(_glfw.win32.dropString,_glfw.win32.dropStringSize);
|
||||
}
|
||||
strcat(_glfw.win32.dropString, utf8str);
|
||||
strcat(_glfw.win32.dropString, "\n");
|
||||
free(utf8str);
|
||||
}
|
||||
|
||||
_glfwInputDrop(window,_glfw.win32.dropString);
|
||||
DragFinish(hDrop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
||||
@@ -865,6 +900,8 @@ static int createWindow(_GLFWwindow* window,
|
||||
window); // Pass object to WM_CREATE
|
||||
|
||||
free(wideTitle);
|
||||
|
||||
DragAcceptFiles(window->win32.handle, TRUE);
|
||||
|
||||
if (!window->win32.handle)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user