1
Window / (SOLVED)My implementation of dragndrop files for window is not working at all.
« on: September 09, 2024, 05:06:35 pm »
Hello. I'm trying to implement dragndrop files functionality into my sf::window for windows 11 using the window handle and WINAPI. So far I have this but it doesn't do anything. The window shows it allows dragndrop but it doesn't receive any path to the dropped files.
int main(int argc,char* argv[])
{
IntRect workarea;
workarea=getWorkArea();
RenderWindow window(VideoMode(workarea.width,workarea.height),"Desk Engine",Style::None);
window.setPosition(Vector2i(0,0));
//Set SFML to allow dragNdrop and hide from taskbar.
WindowHandle handle = window.getSystemHandle();
SetWindowLongPtrA(handle,GWL_EXSTYLE,WS_EX_ACCEPTFILES|WS_EX_TOOLWINDOW);
DragAcceptFiles(handle, TRUE);
while(window.isOpen())
{
Event e;
while(window.pollEvent(e))
{
if(e.type==Event::Closed)
window.close();
}
//Handle DRAG and DROP
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_DROPFILES)
{
HDROP hDrop = (HDROP)msg.wParam;
char filePath[MAX_PATH];
DragQueryFileA(hDrop, 0, filePath, MAX_PATH);
DragFinish(hDrop);
cout << filePath << endl;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//render stuff
}
Thanks in advance!
{
IntRect workarea;
workarea=getWorkArea();
RenderWindow window(VideoMode(workarea.width,workarea.height),"Desk Engine",Style::None);
window.setPosition(Vector2i(0,0));
//Set SFML to allow dragNdrop and hide from taskbar.
WindowHandle handle = window.getSystemHandle();
SetWindowLongPtrA(handle,GWL_EXSTYLE,WS_EX_ACCEPTFILES|WS_EX_TOOLWINDOW);
DragAcceptFiles(handle, TRUE);
while(window.isOpen())
{
Event e;
while(window.pollEvent(e))
{
if(e.type==Event::Closed)
window.close();
}
//Handle DRAG and DROP
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_DROPFILES)
{
HDROP hDrop = (HDROP)msg.wParam;
char filePath[MAX_PATH];
DragQueryFileA(hDrop, 0, filePath, MAX_PATH);
DragFinish(hDrop);
cout << filePath << endl;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//render stuff
}