2021-06-01 19:14:51 +00:00
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <shellapi.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "_cgo_export.h"
|
|
|
|
|
|
|
|
#define droppedFilePathSize 32767
|
|
|
|
|
2021-06-04 15:17:22 +00:00
|
|
|
BOOL dropHookInitialized = FALSE;
|
2021-06-01 19:14:51 +00:00
|
|
|
HHOOK nextHook;
|
|
|
|
|
|
|
|
LRESULT CALLBACK DragAndDropHook(
|
|
|
|
_In_ int nCode,
|
|
|
|
_In_ WPARAM wParam,
|
|
|
|
_In_ LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (nCode < 0 || wParam == 0)
|
|
|
|
return CallNextHookEx(nextHook, nCode, wParam, lParam);
|
|
|
|
|
|
|
|
LPMSG message = (LPMSG)lParam;
|
|
|
|
switch (message->message)
|
|
|
|
{
|
|
|
|
case WM_DROPFILES:
|
|
|
|
{
|
|
|
|
wchar_t droppedFilePath[droppedFilePathSize];
|
|
|
|
|
2021-06-04 15:17:22 +00:00
|
|
|
clearDrop();
|
2021-06-01 19:14:51 +00:00
|
|
|
HDROP drop = (HDROP)message->wParam;
|
|
|
|
UINT numberOfFiles = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
|
|
|
|
for (UINT fileIndex = 0; fileIndex < numberOfFiles; fileIndex++)
|
|
|
|
{
|
|
|
|
UINT length = DragQueryFileW(drop, fileIndex, droppedFilePath, droppedFilePathSize);
|
2021-06-04 15:17:22 +00:00
|
|
|
addDroppedFile(&droppedFilePath[0], length);
|
2021-06-01 19:14:51 +00:00
|
|
|
}
|
2021-06-04 15:17:22 +00:00
|
|
|
POINT position;
|
|
|
|
DragQueryPoint(drop, &position);
|
|
|
|
|
|
|
|
dropFinished(position.x, position.y);
|
2021-06-01 19:14:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CallNextHookEx(nextHook, nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2021-06-04 15:17:22 +00:00
|
|
|
void initDropHook(HWND windowHandle)
|
|
|
|
{
|
|
|
|
if (dropHookInitialized == TRUE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DWORD threadId = GetWindowThreadProcessId(windowHandle, NULL);
|
|
|
|
nextHook = SetWindowsHookEx(WH_GETMESSAGE, DragAndDropHook, NULL, threadId);
|
|
|
|
|
|
|
|
dropHookInitialized = TRUE;
|
|
|
|
}
|
|
|
|
|
2021-06-01 19:14:51 +00:00
|
|
|
void SetDragAndDropHook(void *window)
|
|
|
|
{
|
|
|
|
HWND windowHandle = (HWND)window;
|
2021-06-04 15:17:22 +00:00
|
|
|
initDropHook(windowHandle);
|
|
|
|
|
2021-06-01 19:14:51 +00:00
|
|
|
DragAcceptFiles(windowHandle, TRUE);
|
|
|
|
}
|