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

Author Topic: WM_COMMAND  (Read 1841 times)

0 Members and 1 Guest are viewing this topic.

Doodlemeat

  • Guest
WM_COMMAND
« on: April 02, 2014, 01:20:44 am »
Problem
I have created several menu items using the windows API in the current window. The problem occurs when I have to check if the client pressed on any items. This is done using the WM_COMMAND event.
I tried to use the GetMessage() (as seen below), but whenever I call GetMessage(), all SFML events are blocked/removed/deleted/etc. This is not a desired behavior because I want to be able to use any SFML event while I can press on menu items.

Solution
Extend the sf::Window class with a method called setCommandCallback(std::function p_callback);.
Check my example in the very bottom of the topic for a solution. Maybe make a SFML event of it?
And if this feature is not wished, how can I do it myself? Do I have to edit the source and rebuild it myself?

I am not requsting to add gui, but just WM_COMMAND, or even how to make it avaible.

bool LevelEditorState::update(float dt)
{
        // This will never be true
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
        {
                std::cout << "HI" << std::endl;
        }

        MSG msg;
        while (GetMessageA(&msg, m_stateAsset->windowManager->getWindow()->getSystemHandle(), 0, 0) > 0)
        {
                if (msg.message == WM_COMMAND)
                {
                        switch (LOWORD(msg.wParam))
                        {
                        case ID_FILE_OPEN:
                                openFile();
                                break;
                        case ID_FILE_SAVE:
                                saveFile();
                                break;
                        case ID_FILE_NEW:
                                newFile();
                                break;
                        }
                }

                TranslateMessage(&msg);
                DispatchMessageA(&msg);
        }

        // This will never be true
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
        {
                std::cout << "HI" << std::endl;
        }
        return true;
}

Possible solution?
void commandCallback(MSG message)
{
    switch (LOWORD(msg.wParam))
        {
        case ACTION_1:
            // Do anything
            break;
        case ACTION_2:
            // Do anything
            break;
        case ACTION_3:
            // Do anything
            break;
        }
}

int main()
{
    sf::Window window;
    window.setCommandCallback(&commandCallback); // Add callback
   
    ....
   
    window.removeCommandCallback(); // Remove callback
   
    return ~15;
}
« Last Edit: April 02, 2014, 01:28:56 am by Doodlemeat »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: WM_COMMAND
« Reply #1 on: April 02, 2014, 02:05:14 am »
See this discussion on same topic.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/