From 826931e2c2e61ec7815d25ec33618bfe4aacff0d Mon Sep 17 00:00:00 2001 From: "Denilson M. Amorim" Date: Tue, 23 Jun 2015 19:05:37 -0300 Subject: DroppedFile event for Win32 --- src/api/win32/callback.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/api/win32/callback.rs') diff --git a/src/api/win32/callback.rs b/src/api/win32/callback.rs index 6ac56f3..25beb7b 100644 --- a/src/api/win32/callback.rs +++ b/src/api/win32/callback.rs @@ -3,12 +3,15 @@ use std::ptr; use std::cell::RefCell; use std::sync::mpsc::Sender; use std::sync::{Arc, Mutex}; +use std::ffi::OsString; +use std::os::windows::ffi::OsStringExt; use CursorState; use Event; use super::event; use user32; +use shell32; use winapi; /// There's no parameters passed to the callback function, so it needs to get @@ -249,6 +252,25 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, 0 }, + winapi::WM_DROPFILES => { + use events::Event::DroppedFile; + + let hdrop = wparam as winapi::HDROP; + let mut pathbuf: [u16; winapi::MAX_PATH] = unsafe { mem::uninitialized() }; + let num_drops = shell32::DragQueryFileW(hdrop, 0xFFFFFFFF, ptr::null_mut(), 0); + + for i in 0..num_drops { + let nch = shell32::DragQueryFileW(hdrop, i, pathbuf.as_mut_ptr(), + winapi::MAX_PATH as u32) as usize; + if nch > 0 { + send_event(window, DroppedFile(OsString::from_wide(&pathbuf[0..nch]).into())); + } + } + + shell32::DragFinish(hdrop); + 0 + }, + _ => { user32::DefWindowProcW(window, msg, wparam, lparam) } -- cgit v1.2.3