With
https://github.com/binary1248/SFML/commit/ef593102ba730c300895109125860e5ab59d3c63 you can do what you want:
#include <SFML/Window.hpp>
#include <iostream>
#include <Windows.h>
LONG_PTR originalsfmlcallback = 0x0;
LRESULT CALLBACK mycallback(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_DROPFILES)
{
sf::Window& app = *reinterpret_cast<sf::Window*>(GetWindowLongPtrW(handle, GWLP_USERDATA));
std::cout << "Window position: " << app.getPosition().x << ", " << app.getPosition().y << "\n";
HDROP hdrop = reinterpret_cast<HDROP>(wParam);
POINT p;
p.x = 0;
p.y = 0;
if (DragQueryPoint(hdrop, &p))
std::printf("Point is %d, %d\n", p.x, p.y);
else
std::cout << "Failed to get point" << std::endl;
const UINT filescount = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
for (UINT i = 0; i < filescount; ++i)
{
const UINT bufsize = DragQueryFile(hdrop, i, NULL, 0);
std::wstring str;
str.resize(bufsize + 1);
if (DragQueryFileW(hdrop, i, &str[0], bufsize + 1))
{
std::string stdstr;
sf::Utf8::fromWide(str.begin(), str.end(), std::back_inserter(stdstr));
std::cout << stdstr << std::endl;
}
}
DragFinish(hdrop);
std::cout << "-------------" << std::endl;
}//if WM_DROPFILES
return CallWindowProcW(reinterpret_cast<WNDPROC>(originalsfmlcallback), handle, message, wParam, lParam);
}
int main(int argc, char ** argv)
{
sf::Window app(sf::VideoMode(640u, 480u), "Drag and Drop from USERLAND");
HWND handle = app.getSystemHandle();
DragAcceptFiles(handle, TRUE);
SetWindowLongPtrW(handle, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(&app));
originalsfmlcallback = SetWindowLongPtrW(handle, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(mycallback));
while (app.isOpen())
{
sf::Event eve;
while (app.pollEvent(eve))
{
if (eve.type == sf::Event::Closed)
app.close();
}//while app poll event eve
app.display();
}//while app is open
}
The question is... should I open a pull request in the main repository for this...