mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 10:35:38 +00:00
Added Windows D&D support
This commit is contained in:
parent
18dd603696
commit
90e9c28cbd
|
@ -57,6 +57,8 @@ namespace OpenTK.Platform.Windows
|
|||
using HKEY = System.IntPtr;
|
||||
using PHKEY = System.IntPtr;
|
||||
|
||||
using HDROP = System.IntPtr;
|
||||
|
||||
using LRESULT = System.IntPtr;
|
||||
using LPVOID = System.IntPtr;
|
||||
using LPCTSTR = System.String;
|
||||
|
@ -134,6 +136,25 @@ namespace OpenTK.Platform.Windows
|
|||
{
|
||||
#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,
|
||||
|
|
|
@ -150,6 +150,7 @@ namespace OpenTK.Platform.Windows
|
|||
0, 0, ClientSize.Width, ClientSize.Height,
|
||||
title, options, device, window.Handle),
|
||||
window);
|
||||
Functions.DragAcceptFiles(window.Handle, true);
|
||||
|
||||
exists = true;
|
||||
}
|
||||
|
@ -680,6 +681,29 @@ namespace OpenTK.Platform.Windows
|
|||
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
|
||||
|
@ -754,6 +778,7 @@ namespace OpenTK.Platform.Windows
|
|||
return IntPtr.Zero;
|
||||
|
||||
case WindowMessage.LBUTTONDOWN:
|
||||
Console.WriteLine("ola");
|
||||
HandleLButtonDown(handle, message, wParam, lParam);
|
||||
return IntPtr.Zero;
|
||||
|
||||
|
@ -800,6 +825,10 @@ namespace OpenTK.Platform.Windows
|
|||
HandleKillFocus(handle, message, wParam, lParam);
|
||||
break;
|
||||
|
||||
case WindowMessage.DROPFILES:
|
||||
HandleDropFiles(handle, message, wParam, lParam);
|
||||
break;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Creation / Destruction events
|
||||
|
|
Loading…
Reference in a new issue