[UI] Remove MAX_PATH limit from WM_DROPFILES

Also required const-ifying a file drop message.
This commit is contained in:
Silent 2019-08-31 14:29:32 +02:00 committed by Justin Moore
parent 96a9397349
commit d3a73022fd
4 changed files with 18 additions and 16 deletions

View File

@ -291,9 +291,8 @@ bool EmulatorWindow::Initialize() {
return true; return true;
} }
void EmulatorWindow::FileDrop(wchar_t* filename) { void EmulatorWindow::FileDrop(const wchar_t* filename) {
std::wstring path = filename; auto result = emulator_->LaunchPath(filename);
auto result = emulator_->LaunchPath(path);
if (XFAILED(result)) { if (XFAILED(result)) {
// TODO: Display a message box. // TODO: Display a message box.
XELOGE("Failed to launch target: %.8X", result); XELOGE("Failed to launch target: %.8X", result);

View File

@ -43,7 +43,7 @@ class EmulatorWindow {
bool Initialize(); bool Initialize();
void FileDrop(wchar_t* filename); void FileDrop(const wchar_t* filename);
void FileOpen(); void FileOpen();
void FileClose(); void FileClose();
void ShowContentDirectory(); void ShowContentDirectory();

View File

@ -28,14 +28,14 @@ class UIEvent {
class FileDropEvent : public UIEvent { class FileDropEvent : public UIEvent {
public: public:
FileDropEvent(Window* target, wchar_t* filename) FileDropEvent(Window* target, const wchar_t* filename)
: UIEvent(target), filename_(filename) {} : UIEvent(target), filename_(filename) {}
~FileDropEvent() override = default; ~FileDropEvent() override = default;
wchar_t* filename() const { return filename_; } const wchar_t* filename() const { return filename_; }
private: private:
wchar_t* filename_ = nullptr; const wchar_t* filename_ = nullptr;
}; };
class KeyEvent : public UIEvent { class KeyEvent : public UIEvent {

View File

@ -492,17 +492,20 @@ LRESULT Win32Window::WndProc(HWND hWnd, UINT message, WPARAM wParam,
switch (message) { switch (message) {
case WM_DROPFILES: { case WM_DROPFILES: {
TCHAR lpszFile[MAX_PATH] = {0}; HDROP hDrop = reinterpret_cast<HDROP>(wParam);
UINT uFiles = 0; std::wstring path;
HDROP hDrop = (HDROP)wParam;
// Get number of files dropped // Get required buffer size
uFiles = DragQueryFile(hDrop, -1, NULL, NULL); UINT buf_size = DragQueryFileW(hDrop, 0, nullptr, 0);
if (buf_size > 0) {
path.resize(buf_size + 1); // Give space for a null terminator
// Only getting first file dropped (other files ignored) // Only getting first file dropped (other files ignored)
if (DragQueryFile(hDrop, 0, lpszFile, MAX_PATH)) { if (DragQueryFileW(hDrop, 0, &path[0], buf_size + 1)) {
auto e = FileDropEvent(this, lpszFile); auto e = FileDropEvent(this, path.c_str());
OnFileDrop(&e); OnFileDrop(&e);
} }
}
DragFinish(hDrop); DragFinish(hDrop);
} break; } break;