thingybingytie
thingybingytie

Reputation: 190

Selecting dragging and dropping a file into GLFW application from Windows

So basically i am interested to know which Windows api would i need to know about in order to be able to select a file with mouse in Windows and drag and drop it into my application window

My application window will be handled by GLFW, and it basically processes image formats but that's not important

All I am interested to find out is how to do this in Windows

Basically i have an idea that i have to reference the Windows API , and utilise some of their functions/methods and to port the files from Windows application to my application through some pipeline

SO if you can direct me to the correct API and a brief , method/idea how to do this and how this works

Thanks

Upvotes: 2

Views: 5539

Answers (2)

Rotem
Rotem

Reputation: 21917

Since you are using GLFW, why not use the native method of handling drag & drop in GLFW?

If you wish to receive the paths of files and/or directories dropped on a window, set a file drop callback.

glfwSetDropCallback(window, drop_callback);

The callback function receives an array of paths encoded as UTF-8.

void drop_callback(GLFWwindow* window, int count, const char** paths)
{
int i;
for (i = 0;  i < count;  i++)
    handle_dropped_file(paths[i]);
}

The path array and its strings are only valid until the file drop callback returns, as they may have been generated specifically for that event. You need to make a deep copy of the array if you want to keep the paths.

Upvotes: 8

c-smile
c-smile

Reputation: 27450

You just need to handle WM_DROPFILES message.

In order to receive that you shall call DragAcceptFiles on your window to enable it as D&D target.

Upvotes: 1

Related Questions