I figured out some basic code for a modal window loop. Seemed to work ok, as was trying to figure it out and found this thread. If it helps?
#include <SFML/Graphics.hpp>
/*
https://stackoverflow.com/questions/26741841/how-does-a-modal-dialogs-message-pump-interact-with-the-main-application-messag
They run on the same thread. The modal dialog spawns a nested message loop.
Both the nested message loop and the main application's message loop (or rather message handlers) are siamese twins in crime:
If one doesn't play by the rules, the respective other will suffer as well. – IInspectable
*/
//call from child
void mainWinMSGHandle(sf::Window &window, sf::Window &child);
void createPopUpWindow(sf::Window *parent, int num)
{
sf::RenderWindow popUpWindow(sf::VideoMode(320,240), "HI " + std::to_string(num), sf::Style::Close);
popUpWindow.setPosition(parent->getPosition() + sf::Vector2i(100,100));
sf::Event event;
while (popUpWindow.isOpen())
{
popUpWindow.clear(sf::Color::Cyan);
popUpWindow.display();
while(popUpWindow.pollEvent(event))
{
if(event.type == sf::Event::Closed)
popUpWindow.close();
if(event.type == sf::Event::LostFocus)
{
if(parent->hasFocus())
popUpWindow.requestFocus();
}
}
mainWinMSGHandle(*parent, popUpWindow);
sf::sleep(sf::milliseconds(1));
}
}
//child message loop blocking main window message loop so need to handle main from child
void mainWinMSGHandle(sf::Window &window, sf::Window &child)
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
child.close();
window.close();
}
if(event.type == sf::Event::GainedFocus)
{
child.requestFocus();
}
}
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800,600),"Main Window");
sf::Event event;
int n = 0;
while (window.isOpen())
{
window.clear(sf::Color::Magenta);
window.display();
window.waitEvent(event);
if(event.type == sf::Event::Closed)
{
window.close();
}
if(event.type == sf::Event::MouseButtonPressed)
{
createPopUpWindow(&window, n++);
}
}
return 0;
}