You're passing
NULL has the window handle, so there's no connection between the window an the inserted event pump.
SFML already implements an event pump, so you can't just write another one next to it, but you'll have to insert your own callback for event processing like this:
#include <SFML/Graphics.hpp>
#include <Windows.h>
LONG_PTR SfmlEventCallback = 0x0;
LRESULT CALLBACK CustomEventCallback(HWND handle, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_MENU...)
{
// Your event handling
}
return CallWindowProcW(reinterpret_cast<WNDPROC>(SfmlEventCallback), handle, message, wParam, lParam);
}
int main()
{
auto app = sf::RenderWindow{ { 640u, 480u }, "Custom Event Handling" };
HWND handle = app.getSystemHandle();
SfmlEventCallback = SetWindowLongPtrW(handle, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(CustomEventCallback));
while (app.isOpen())
{
for (auto event = sf::Event{}; app.pollEvent(event);)
{
if (event.type == sf::Event::Closed)
{
app.close();
}
}
app.clear();
app.display();
}
}
And here's some code from FRex for a custom file drop handling:
#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
}