Add file drop functionality

Adds the ability to drag and drop files from windows in order to attempt
to execute them
This commit is contained in:
Leighton Hancock
2016-11-14 16:50:58 +13:00
parent f5168c5768
commit 524ba0c88c
7 changed files with 51 additions and 0 deletions

View File

@@ -101,6 +101,8 @@ bool Win32Window::OnCreate() {
// Enable DWM elevation.
EnableMMCSS();
// Enable file dragging from external sources
DragAcceptFiles(hwnd_, true);
ShowWindow(hwnd_, SW_SHOWNORMAL);
UpdateWindow(hwnd_);
@@ -378,6 +380,21 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
}
switch (message) {
case WM_DROPFILES: {
TCHAR lpszFile[MAX_PATH] = {0};
UINT uFiles = 0;
HDROP hDrop = (HDROP)wParam;
// Get number of files dropped
uFiles = DragQueryFile(hDrop, -1, NULL, NULL);
// Only getting first file dropped (other files ignored)
if (DragQueryFile(hDrop, 0, lpszFile, MAX_PATH)) {
auto e = FileDropEvent(this, lpszFile);
OnFileDrop(&e);
}
DragFinish(hDrop);
} break;
case WM_NCCREATE:
break;
case WM_CREATE: