Skip to content

How to listen for application close (X) event on PC #2285

Answered by rh101
NgVThangBz asked this question in Q&A
Discussion options

You must be logged in to vote

If you search the code for the event, you'll see that it is sent out from here:

void GLViewImpl::onGLFWWindowCloseCallback(GLFWwindow* window)
{
    bool isClose = true;
    Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_CLOSE, &isClose);
    if (isClose == false)
    {
        glfwSetWindowShouldClose(window, 0);
    }
}

It passes a pointer to a bool, which is used to control if it should proceed with the closure of the window. So, if you set it to false, it should stop the window from closing. For example:

_eventListener = Director::getInstance()->getEventDispatcher()->addCustomEventListener(GLViewImpl::EVENT_WINDOW_CLOSE,
    [this](EventCu…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@NgVThangBz
Comment options

Comment options

You must be logged in to vote
7 replies
@rh101
Comment options

rh101 Dec 24, 2024
Collaborator

Answer selected by NgVThangBz
@NgVThangBz
Comment options

@rh101
Comment options

rh101 Dec 24, 2024
Collaborator

@NgVThangBz
Comment options

@rh101
Comment options

rh101 Dec 24, 2024
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants