Unity windows build penceresine her türlü dosyayı sürükleyip bırakıp dosyayı alabiliyorum fakat outlook mailini sürükleyip bırakamıyorum.

Serhat Denli 0 Reputation points
2023-07-29T10:00:08.6533333+00:00

Bir unity projem için windows platformuna özel drag&drop scripti kullanmaktayım. Herhangi bir klasör, video, resim için çalışıyor fakat outlook mailini sürükleyip bırakamıyorum.

using System;
using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;

public class FileDropHandler2 : MonoBehaviour
{

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct DROPFILES
    {
        public Int32 pFiles;
        public Int32 X;
        public Int32 Y;
        public Int32 fNC;
        public Int32 fWide;
    }

    [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
    public static extern void DragAcceptFiles(IntPtr hWnd, bool bAccept);

    [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
    public static extern UInt32 DragQueryFile(IntPtr hDrop, UInt32 iFile, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszFile, UInt32 cch);

    [DllImport("shell32.dll")]
    public static extern void DragFinish(IntPtr hDrop);

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();

    [DllImport("user32.dll")]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    private const int WM_DROPFILES = 0x0233;

    private IntPtr handle;

    private void Start()
    {
        handle = GetActiveWindowHandle();
        DragAcceptFiles(handle, true);
    }

    private void OnApplicationQuit()
    {
        DragAcceptFiles(handle, false);
    }

    private void Update()
    {
        if (IsFileDropped())
        {
            HandleDroppedFiles();
        }
    }

    private bool IsFileDropped()
    {
        return DragQueryFileCount() > 0;
    }

    private uint DragQueryFileCount()
    {
        return DragQueryFile(handle, 0xFFFFFFFF, null, 0);
    }

    private void HandleDroppedFiles()
    {
        uint fileCount = DragQueryFileCount();
        if (fileCount > 0)
        {
            StringBuilder fileNameBuffer = new StringBuilder(255);
            for (uint i = 0; i < fileCount; i++)
            {
                uint bufferSize = (uint)fileNameBuffer.Capacity + 1;
                DragQueryFile(handle, i, fileNameBuffer, bufferSize);
                string filePath = fileNameBuffer.ToString();
                Debug.Log("Dropped file path: " + filePath);
            }

            DragFinish(handle);
        }
    }

    private IntPtr GetActiveWindowHandle()
    {
        IntPtr handle = IntPtr.Zero;
        if (Application.isEditor)
        {
            handle = GetActiveEditorWindowHandle();
        }
        else
        {
            handle = GetActivePlayerWindowHandle();
        }
        return handle;
    }

    private IntPtr GetActiveEditorWindowHandle()
    {
        return GetForegroundWindow();
    }

    private IntPtr GetActivePlayerWindowHandle()
    {
        return FindWindow(null, Application.productName);
    }


}

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,795 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,254 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,481 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,726 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,526 Reputation points
    2023-07-31T10:26:19.5266667+00:00

    Hello,

    Thank you for your question and for reaching out with your question today.

    The issue you are facing with not being able to drag and drop an Outlook email into your Unity project's Windows build might be related to the limitations of the drag and drop functionality in Unity when it comes to certain types of data.

    Unity's drag and drop functionality is primarily designed to handle files and data that can be represented as files (e.g., images, videos, folders, etc.). Outlook emails are more complex data structures that might not be directly supported by Unity's drag and drop system.

    To handle dragging and dropping Outlook emails or other complex data types into your Unity project, you might need to use different approaches. Here are some suggestions:

    1. Clipboard: You can try using the clipboard to copy the email content in Outlook and then paste it into your Unity application. Unity provides access to the clipboard through GUIUtility.systemCopyBuffer. However, this might not capture all the rich content of an Outlook email.
    2. Custom File Format: Convert the Outlook email into a custom file format, such as JSON or XML, and save it as a file. Then, you can drag and drop this custom file format into your Unity project and parse the data accordingly.
    3. Outlook Add-in: If you want more direct integration with Outlook, consider developing an Outlook add-in that communicates with your Unity application through web services or other means.

    Keep in mind that these suggestions might require additional development and might not provide a seamless drag and drop experience like handling regular files in Unity. Nonetheless, they could offer a way to transfer Outlook email data into your Unity project.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    If the reply was helpful, please don’t forget to upvote or accept as answer.

    Best regards.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.