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

Author Topic: No events are being caught with SFML 2.1 + Win32?  (Read 1759 times)

0 Members and 1 Guest are viewing this topic.

DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
No events are being caught with SFML 2.1 + Win32?
« on: October 17, 2014, 03:32:32 am »
Hi there,

I have the following code:

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Test",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
        NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    Msg.message = static_cast<UINT>(~WM_QUIT);

    SE::Engine engine(hwnd);

        //For finding delta time
        sf::Clock deltaClock;

        sf::Time lastUpdate = sf::Time::Zero;

        //60fps max
        sf::Time timePerFrame = sf::seconds(1.f / 60.f);

    while (Msg.message != WM_QUIT)
    {
        if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }

        else
        {
            while (engine.running())
            {
                lastUpdate += deltaClock.restart();

                while (lastUpdate > timePerFrame)
                {
                    lastUpdate -= timePerFrame;

                    engine.update(timePerFrame);
                    engine.render();
                }
            }
        }

ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    return Msg.wParam;
    }

And engine.update(timePerFrame) is basically along the lines of this:

sf::Event evt;

while (SceneManager::getWindow().pollEvent(evt))
            m_input_manager.update(dt, evt);
}

I tried referencing several posts and the integrating SFML 1.6 into Win32, but they're dated and I can't seem to get it to work. If anyone has any ideas I would be extremely grateful.

Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
AW: No events are being caught with SFML 2.1 + Win32?
« Reply #1 on: October 17, 2014, 08:12:18 am »
Why exactly do you need to handle events on your own?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: No events are being caught with SFML 2.1 + Win32?
« Reply #2 on: October 17, 2014, 08:41:18 am »
Try to catch other events, the close and destroy events are "special".

And if you run your own Windows event loop, it shouldn't be blocked while your engine is running. If you run it only for the window, then you don't have to do it, window.pollEvent already does the job.
Laurent Gomila - SFML developer

DevilEdge

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: No events are being caught with SFML 2.1 + Win32?
« Reply #3 on: October 17, 2014, 12:54:58 pm »
Thanks guys, I resolved the issue.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: No events are being caught with SFML 2.1 + Win32?
« Reply #4 on: October 17, 2014, 02:22:47 pm »
Can you tell us how?

The most annoying thing is when you search for an issue, find a forum thread with exactly the same problem description, but no solution ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything