[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;
}
void EmulatorWindow::FileDrop(wchar_t* filename) {
std::wstring path = filename;
auto result = emulator_->LaunchPath(path);
void EmulatorWindow::FileDrop(const wchar_t* filename) {
auto result = emulator_->LaunchPath(filename);
if (XFAILED(result)) {
// TODO: Display a message box.
XELOGE("Failed to launch target: %.8X", result);

View File

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

View File

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

View File

@ -492,16 +492,19 @@ 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);
HDROP hDrop = reinterpret_cast<HDROP>(wParam);
std::wstring path;
// Only getting first file dropped (other files ignored)
if (DragQueryFile(hDrop, 0, lpszFile, MAX_PATH)) {
auto e = FileDropEvent(this, lpszFile);
OnFileDrop(&e);
// Get required buffer size
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)
if (DragQueryFileW(hDrop, 0, &path[0], buf_size + 1)) {
auto e = FileDropEvent(this, path.c_str());
OnFileDrop(&e);
}
}
DragFinish(hDrop);