[UI] Fix window file drop handling.

This commit is contained in:
gibbed 2020-04-10 08:30:38 -05:00 committed by Rick Gibbed
parent e0f3458026
commit 112c66df69
1 changed files with 18 additions and 14 deletions

View File

@ -498,22 +498,26 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
switch (message) { switch (message) {
case WM_DROPFILES: { case WM_DROPFILES: {
HDROP hDrop = reinterpret_cast<HDROP>(wParam); HDROP drop_handle = reinterpret_cast<HDROP>(wParam);
std::u16string path; auto drop_count = DragQueryFileW(drop_handle, 0xFFFFFFFFu, nullptr, 0);
if (drop_count > 0) {
// Get required buffer size // Get required buffer size
UINT buf_size = DragQueryFileW(hDrop, 0, nullptr, 0); UINT path_size = DragQueryFileW(drop_handle, 0, nullptr, 0);
if (buf_size > 0) { if (path_size > 0 && path_size < 0xFFFFFFFFu) {
path.resize(buf_size + 1); // Give space for a null terminator std::u16string path;
++path_size; // Ensure space for the null terminator
path.resize(path_size); // Reserve space
// Only getting first file dropped (other files ignored) // Only getting first file dropped (other files ignored)
if (DragQueryFileW(hDrop, 0, (LPWSTR)&path[0], buf_size + 1)) { path_size =
DragQueryFileW(drop_handle, 0, (LPWSTR)&path[0], path_size);
if (path_size > 0) {
path.resize(path_size); // Will drop the null terminator
auto e = FileDropEvent(this, xe::to_path(path)); auto e = FileDropEvent(this, xe::to_path(path));
OnFileDrop(&e); OnFileDrop(&e);
} }
} }
}
DragFinish(hDrop); DragFinish(drop_handle);
} break; } break;
case WM_NCCREATE: { case WM_NCCREATE: {
// Tell Windows to automatically scale non-client areas on different DPIs. // Tell Windows to automatically scale non-client areas on different DPIs.