alt-f4 disable

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

alt-f4 disable

Post by 3DModelerMan »

Can I disable exiting with alt-f4 without modifying the source code? Or should I just do that and rebuild at the end of my project?
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

You need to edit CIrrDeviceWin32.cpp and change how the WM_CLOSE event is handled.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Could you not swallow it in your event receiver and that would prevent it being handled anywhere else? Or does it get read before the user event receiver?
Image Image Image
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

The left alt key doesn't get passed to Irrlicht in windowed mode, it activates the menu instead. Same applies to the key-up event for the escape key, they're special keys used internally by Windows and have to be disabled by some command I think
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Could you swallow just the F4 key to prevent it then?
Image Image Image
Dragonazul
Posts: 24
Joined: Sun Sep 23, 2007 9:45 pm
Location: Spain

Post by Dragonazul »

I have similar problem with the close button of the main window.

I have modify a few the CIrrDeviceWin32.cpp:

Code: Select all

-	/*case WM_DESTROY:
-		PostQuitMessage(0);
-		return 0;*/

	case WM_SYSCOMMAND:
		// prevent screensaver or monitor powersave mode from starting
		if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
			(wParam & 0xFFF0) == SC_MONITORPOWER)
			return 0;
		break;

	case WM_USER:
		event.EventType = irr::EET_USER_EVENT;
		event.UserEvent.UserData1 = (irr::s32)wParam;
		event.UserEvent.UserData2 = (irr::s32)lParam;
		dev = getDeviceFromHWnd(hWnd);

		if (dev)
			dev->postEventFromUser(event);

		return 0;
	}
+	if (message != WM_QUIT && message != WM_CLOSE  && message != WM_DESTROY){
		return DefWindowProc(hWnd, message, wParam, lParam);
+	}
+	else{
+		printf("Close Device. ¿Create new event type?\n");
+	}
	return 0;
}
this works and the window don't close with neither the close button or the alt+F4. I suppose I can create a new event type EGET_USER_CLOSE_WINDOW and then capture it in my application and close de window. But I don't know how to close my window my best is to call:: Device->closeDevice(); But it only close the window and not the console...

another problem is that device run allways return true....

any idea of how to close the application correctly???
Dragonazul
Posts: 24
Joined: Sun Sep 23, 2007 9:45 pm
Location: Spain

Post by Dragonazul »

Hi all.

A lot of time receiving is time to contribute...
Althoug you caught the WM_QUIT, WM_DESTROY... it don't works, when you caught this event the main windows has been already close.

Is necessary to caught a WM_SYSCOMMAND with wParam = SC_CLOSE that generate the next close events (WM_CLOSE. WM_QUIT...)

I put here my solution y never close the application with Alt+F4 Or close window button.

File CIrrDeviceWin32.cpp

Code: Select all

    case WM_SYSCOMMAND:
		// prevent screensaver or monitor powersave mode from starting
		if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
			(wParam & 0xFFF0) == SC_MONITORPOWER)
			return 0;
+	      //Event capture, close window
+		if((wParam & 0xF060) == SC_CLOSE){
+               //Generate new event type
+			event.EventType = irr::EET_GUI_EVENT;
+			event.GUIEvent.EventType = irr::gui::EGET_MAIN_WINDOW_CLOSED;
+			dev = getDeviceFromHWnd(hWnd);
+			if (dev)
+				dev->postEventFromUser(event);
+			return 0;
+		}
		break;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
Now the only way to close the application is caught EGET_MAIN_WINDOW_CLOSED and call to Device->closeDevice();

Code: Select all

		if (event.EventType == irr::EET_GUI_EVENT)
			if(event.GUIEvent.EventType == irr::gui::EGET_MAIN_WINDOW_CLOSED)
				Device->closeDevice();

I Hope this help
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Cool, thank you Dragonazul. We may eventually add device events into Irrlicht (close, resize, destroy, add/remove drive, etc) and when we do this will certainly be useful :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Dragonazul
Posts: 24
Joined: Sun Sep 23, 2007 9:45 pm
Location: Spain

Post by Dragonazul »

Thanks Bitplane. I'm happy to help.
This is a fantastic community
Post Reply