ProblemI 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.
SolutionExtend 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;
}