using HKEY = System.IntPtr;
using PHKEY = System.IntPtr;
+ using HDROP = System.IntPtr;
+
using LRESULT = System.IntPtr;
using LPVOID = System.IntPtr;
using LPCTSTR = System.String;
{
#region Window functions
+ [DllImport("shell32.dll")]
+ internal static extern bool DragAcceptFiles(
+ IntPtr handle,
+ [MarshalAs(UnmanagedType.Bool)] bool fAccept
+ );
+
+ [DllImport("shell32.dll")]
+ internal static extern uint DragQueryFile(
+ HDROP hDrop,
+ uint iFile,
+ IntPtr lpszFile,
+ uint cch
+ );
+
+ [DllImport("shell32.dll")]
+ internal static extern void DragFinish(
+ HDROP hDrop
+ );
+
#region SetWindowPos
// WINUSERAPI BOOL WINAPI SetWindowPos(__in HWND hWnd, __in_opt HWND hWndInsertAfter,
0, 0, ClientSize.Width, ClientSize.Height,
title, options, device, window.Handle),
window);
+ Functions.DragAcceptFiles(window.Handle, true);
exists = true;
}
OnClosed(EventArgs.Empty);
}
+ void HandleDropFiles(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
+ {
+ IntPtr hDrop = wParam;
+ uint filesCounter = Functions.DragQueryFile(hDrop, 0xFFFFFFFF, IntPtr.Zero, 0);
+ for (uint i = 0; i < filesCounter; ++i)
+ {
+ // Don't forget about \0 at the end
+ uint fileNameSize = Functions.DragQueryFile(hDrop, i, IntPtr.Zero, 0) + 1;
+ byte [] byteArray = new byte [fileNameSize];
+ IntPtr str = Marshal.AllocHGlobal((int)fileNameSize);
+
+ Functions.DragQueryFile(hDrop, i, str, fileNameSize);
+
+ Marshal.Copy(str, byteArray, 0, (int)(fileNameSize - 1));
+ string dropString = System.Text.Encoding.UTF8.GetString(byteArray);
+ OnDrop(dropString);
+
+ Marshal.FreeHGlobal(str);
+ }
+
+ Functions.DragFinish(hDrop);
+ }
+
#endregion
#region WindowProcedure
return IntPtr.Zero;
case WindowMessage.LBUTTONDOWN:
+ Console.WriteLine("ola");
HandleLButtonDown(handle, message, wParam, lParam);
return IntPtr.Zero;
HandleKillFocus(handle, message, wParam, lParam);
break;
+ case WindowMessage.DROPFILES:
+ HandleDropFiles(handle, message, wParam, lParam);
+ break;
+
#endregion
#region Creation / Destruction events