Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Extending Gosu / Disable 'close' button [WINDOWS]
- By AmIMeYet Date 2009-05-17 13:02 Edited 2009-05-18 18:41
"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
- By jlnr (dev) Date 2009-05-17 15:34
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.
- By AmIMeYet Date 2009-05-17 19:50 Edited 2009-05-18 14:18

>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?

Ah well, off to bed
- By jlnr (dev) Date 2009-05-17 22:46
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 "> " :)
- By AmIMeYet Date 2009-05-18 15:11
Can you tell me a bit about how you spawn the gosu window?
I think the answer lies there.. or didn't you have to specify any WindowProc?

I think the only way to do it, for me, is to use some dll.. but I really don't want to.
- By jlnr (dev) Date 2009-05-18 16:26
The C++ file for that is:

http://gosu.googlecode.com/svn/trunk/GosuImpl/WindowWin.cpp

But you shouldn't have to know about my WndProc to put your own one in :)
- By AmIMeYet Date 2009-05-18 17:32 Edited 2009-05-18 17:38
Wow, Gosu has a public source? .. too bad I don't know C++
Therefore I don't have a clue how to insert a custom WindowProc.

Any chance of you implementing some kind of handle for me real quick? :D
Hahah.. no rush, no rush

Also, can I deduce (?) that "Gosu::Window" is  the name of the window class? (To improve my the reason_for_this_topic-snippet thing)

Also, I saw image-icon.. does Gosu support this?
- By jlnr (dev) Date 2009-05-18 18:05
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.
- By AmIMeYet Date 2009-05-18 19:11 Edited 2009-05-18 19:19
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
Attachment: wndproc.png (0B)
- By jlnr (dev) Date 2009-05-18 20:30
Well, no EXE, no icon :)

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 :)
- By carno Date 2013-06-06 06:46
I know it's been years but it would be nice to actually have this feature implemented :P
Up Topic Gosu / Extending Gosu / Disable 'close' button [WINDOWS]

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill