SFML community forums

Help => Window => Topic started by: skyddr8511 on October 15, 2024, 09:46:56 am

Title: I want to add my own iocp in sfml. How can I do that? I need to intercept the me
Post by: skyddr8511 on October 15, 2024, 09:46:56 am
I want to add my own iocp in sfml. How can I do that? I need to intercept the message
Title: Re: I want to add my own iocp in sfml. How can I do that? I need to intercept the me
Post by: skyddr8511 on October 15, 2024, 09:49:36 am
For example, I need to use WSAAsyncSelect, which is the network programming mode of window messages
How is it used in SFML? If you need to overload the PreTranslateMessage function, please give a code example
Title: Re: I want to add my own iocp in sfml. How can I do that? I need to intercept the me
Post by: skyddr8511 on October 15, 2024, 09:54:24 am
Using SetWindowLongPtr??????????
(click to show/hide)
Title: while (m_window.pollEvent(event)) How to obtain it
Post by: skyddr8511 on October 15, 2024, 10:14:41 am
while (m_window.pollEvent(event))   How to obtain it
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam, LPARAM lParam)
Title: Re: I want to add my own iocp in sfml. How can I do that? I need to intercept the me
Post by: eXpl0it3r on October 19, 2024, 09:57:52 pm
I have no idea about iocp, but yes, if you need to hook into the event queue on Windows you can attach your own handler 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();
    }
}