Alt + F4


22-07-2007 22:21:47

How can i disable closing my application by pressing alt+f4 ? I'm using the code from Mogre.Demo.ExampleApplication


22-07-2007 22:50:55


The only way I can think on the top of my head would be to subclass the Window and intercept the WM_CLOSE message. Right now, if you look in OgreWindowEventUtilities.cpp, you can see that there is nothing preventing the window from closing :

case WM_CLOSE:
for( ; start != end; ++start )
return 0;

So, here is what you do :

1) Get the window handle (HWND) with RenderWindow.GetCustomAttribute("WINDOW", ...).

2) Get the current WNDPROC with GetWindowLong(...) (You will need some DllImports[] here)

3) Create a new WNDPROC that intercepts the WM_CLOSE message and forwards all the other messages to the old WNDPROC.

4) Use SetWindowLong() to assign your new WNDPROC.

5) There you go! The window will not close anymore. Moreover, you will have the control on what to do when a window gets closed.

If you are not familiar with Win32, let me know, I can guide you through it. Shouldnt be more than a 20-30 lines of C# code i guess.