"Is your game troubled by that pesky close button at the top? Well, not anymore, with my DisableCloseButton-izer Gold Deluxe Special edition, you can disable it in an instant!" -That's what it would sound like if I where one of those annoying salesmen on tv.
Now, this snippet might not be of use to everyone, but for my current project (improving my MapEditor), I really needed it. What this does is disable/gray out the close-button's from your window's titlebar, the titlebar's context-menu, and the taskbar's context-menu..
(See attachment)
Remember, people can still close your window by pressing ALT+F4, or going into the task-manager. You ofcourse always have the option to close it with gosu's 'close' method.
All you have to do, is add my snippet (the bottom of the post) to your window class, and call it in your initialize method. Another important thing is to change self.caption at least once BEFORE calling disable_close_button. If you don't do this, the snippet won't be able to recognize the game-window.
=====
def disable_close_button case Config::CONFIG['host_os'] when /mswin|windows/i @getWindow = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L') @wnd = @getWindow.call(0,0,"Gosu::Window",self.caption) @getMenu = Win32API.new('user32','GetSystemMenu','%w(p,p)','L') @menu = @getMenu.call(@wnd,0) @enable = Win32API.new('user32','EnableMenuItem','%w(p,i,i)','L') @enable.call(@menu,0xf060,0x0001) when /linux/i p "DISABLE CLOSE: sorry, linux is not supported for this method" when /sunos|solaris/i p "DISABLE CLOSE: sorry, solaris is not supported for this method" else p "DISABLE CLOSE: sorry, your operating system is not supported for this method" end end
Nice snippet :) A more advanced method would be to subclass the Gosu window with a new WndProc and provide a new can_close? callback that is called on WM_CLOSE(?). This one can then ask for confirmation using MessageBox(). My old WinAPI tools always did something like that that. If I ever find the time to integrate Gosu with a windowing toolkit, I'll make sure that this is possible in a cleaner way.
What saddens me though is that you check for Solaris, but not for OS X ;) Maybe the same is possible there using RubyCocoa, but I couldn't find a nice looking API at a quick skimming over the instance and delegate methods.
>A more advanced method would be to subclass the Gosu window with a new WndProc and provide a new can_close? callback that is called on WM_CLOSE(?). This one can >then ask for confirmation using MessageBox(). My old WinAPI tools always did something like that that. If I ever find the time to integrate Gosu with a windowing toolkit, I'll make >sure that this is possible in a cleaner way.
Yeah, I'd like it if you would do_it/look_into_it sometime .. because I have no idea how to do what you just said..
I've read about the WM_CLOSE notification and stuff, but I have no idea how to ever implement this in the window class. I also wondered what a window could ever do to stop the window from closing... .. .. oh wait, I just read [url=http://msdn.microsoft.com/en-us/library/ms632617(VS.85).aspx]http://msdn.microsoft.com/en-us/library/ms632617(VS.85).aspx[/url] again.. So how would one override the WndProc (the equivalent to the msdn callback stuff right) ? What would be it's content?
>What saddens me though is that you check for Solaris, but not for OS X ;) Maybe the same is possible there using RubyCocoa, but I couldn't find a nice looking API at a quick >skimming over the instance and delegate methods.
Yeah sorry, I ripped that case statement from some other site :) I also thought about OS(X) API's, but I don't know ANYTHING about that. Couldn't even find any relevant documentation.
Edit: Oh god, noooOO! Rubygame has stuff for this ! :( Rubygame is Gosu's enemy, right?
I don't know how, but you would have to create a WndProc callback and retrieve the current one, then do the check in yours and pass everything else to the old WndProc. This is so common that I bet the Win32 extension has something to support that.
And the Rubygame guys are onle the bad ones when we're in the mid of a Ruby Weekend competition ;)
BTW, this board supports e-mail style quoting using "> " :)
Oh right, the Window class is and always has been "Gosu::Window". Of course, a totally gosu Gosu user could have several of them open at once ;)
Gosu will use the first icon resource it can find in the current EXE file. So if you want to give your game an icon, you can use ResourceHacker to hack it in there. Maybe should be part of the DeploymentOnWindows page or what it's called :) This is a rather new feature though.
Ah, yes, I updated the code with @getWindow.call(0,0,"Gosu::Window",self.caption).
About the icon, so you would basically NEED RubyScript2Exe? :D
So, any chance of implementation of <@attachement>? Edit: In the screenshot: "hook? close" (and minimize) should be "hook?(rb_close)", where rb_ means it's a users ruby code
And the attached proposal is exactly what could be done by overriding the WndProc. Maybe I'll give that a try later. I don't want to extend Gosu's interface in any direction before I touch Shoes :)