Created
September 20, 2017 14:27
-
-
Save FRex/3f7b8d1ad1289a2117553ff3702f04af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ | |
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(DragQueryFile(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); | |
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment