Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I want to add my own iocp in sfml. How can I do that? I need to intercept the me  (Read 2289 times)

0 Members and 1 Guest are viewing this topic.

skyddr8511

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
I want to add my own iocp in sfml. How can I do that? I need to intercept the message

skyddr8511

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
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

skyddr8511

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Using SetWindowLongPtr??????????
(click to show/hide)

skyddr8511

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
while (m_window.pollEvent(event)) How to obtain it
« Reply #3 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)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
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();
    }
}
 
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything