How do I disable the X (close) button on the window


I have seen some programs that have disabled the X button (on Windows). I was wondering if there was a way to do this in oF.

Another solution would be being able to catch the window close action produced by clicking the X. Is this possible in oF?


This link might help. Provided that you’re using GLFW as your windowing system.

this still works ? will it work crossplatform ?


You can also try the decorated=False parameter when you do the window setup. The X will not be there, but you cannot move the window easily without writing it manually in mouseDragged()

Nope, I need the X button and show a “Do you want to save before leaving” message. Thanks

You could add to ofApp.h:

void exit();

And to ofApp.cpp

void ofApp::exit(){
  //this will get called right before the app closes. 
  //add your pop up dialog here
1 Like

I remember using glfwWindowCallback functionaity.
I used that to disable closing the app, when the X button was pressed. You can see how its done in the glfw docs:

I did those because I did not found a way to stop the closing process inside ofApp:exit(). Maybe there is and I’m not aware of that…

For you use case maybe it’s not the best solution, but maybe someone finds it useful searching for this topic.


Hi everybody, sorry for not replying sooner. I’ve finally came to a solution that i got from an old post from @arturo

It just need to be updated a little bit:

// On setup() I added:
ofAddListener(ofEvents().exit, this, &ofApp::tryToExit);

// And then...

bool ofApp::tryToExit(ofEventArgs& args)
    /* For this to work you must change oF source code:
     * File: libs/openFrameworks/app/ofAppGLFWWindow.cpp

     Change 'exit_cb' function to:

     void ofAppGLFWWindow::exit_cb(GLFWwindow* windowP_){
        ofAppGLFWWindow * instance = setCurrent(windowP_);
            glfwSetWindowShouldClose(windowP_, false);
    if (exit_condition) {
         return false;
    } else {
         return true;

In my case I wanted to ask the user if they want to save before closing. So I had to always return true. After that I just used ofExit(0) to quit.

Just be aware that ofApp::exit() will be called each time the “x” is clicked (and when ofExit(0) as well) !

The real bummer is that oF source code have to be changed and this is not built in