Minimise Help

BlitzPlus Forums/BlitzPlus Programming/Minimise Help

Grey Alien(Posted 2005) [#1]
So far all the Blitz programming I have done has been in graphics mode but I just added a windowed mode to my game by calling Graphics 800,600,32,2. the 2 flag on the end puts in in a window. Please excuse the simplicity of my questions...

How do I add a minimise and close button to the title bar? And how do I call the minimise function in code (i.e. when the user presses a "Boss" key)?

Will Alt+F4 auto close the app when an X is on the title bar or will an event get raised?

thanks


Snarkbait(Posted 2005) [#2]
to add minimize to the window:

; add minimize button 
Wlong = User32_GetWindowLong(hWND, -16)
Wlong = Wlong Or $20000
User32_SetWindowLong(hWND, -16, Wlong)



You need these commands in your 'user32.decls'

User32_SetWindowLong% (hwnd%, nIndex%, dwNewLong%) : "SetWindowLongA"
User32_GetWindowLong%(hwnd%, nIndex%): "GetWindowLongA"


Grey Alien(Posted 2005) [#3]
Thanks, I'll try that. Anyone able to answer my other questions?


Grey Alien(Posted 2005) [#4]
Hmm, I made a user32.decls file and stuck
.lib "user32.dll" 
at the top of it. I added the suggested code to the app, but I am at a loss as how to get the handle of my game window. Bear in mind I created it with graphics (and flag 2 in the end) not CreateWindow. Any help will be appreciated. Thanks


WolRon(Posted 2005) [#5]
Haven't tried it, but will QueryObject() work for a Graphics window? maybe with query_id 2?


Grey Alien(Posted 2005) [#6]
This
Notify(QueryObject(BackBuffer(), 2))
returns 0, so I guess it doesn't work. If you make a window with Graphics, Blitz must have stored a handle somewhere so it can close it at the end! But how can I access it. Failing that I'll have to use CreateWindow (which is new to me in Blitz) but you can't use backbuffer and flip can you, which would mean some horrid re-writing.


VIP3R(Posted 2005) [#7]

Failing that I'll have to use CreateWindow (which is new to me in Blitz) but you can't use backbuffer and flip can you


You can create a canvas within the window and use that in the same manner ;)

Or try this...

AppTitle "Tetris"

Handle=FindWindowA("","Tetris")


.lib "user32.dll"
FindWindowA%(NullString,WindowText$):"FindWindowA"




Grey Alien(Posted 2005) [#8]
Thanks VIP3R, that does indeed get the handle of the Blitz Graphic window. I then called a modified version of Snarkbait's code as follows:

Wlong = User32_GetWindowLong(TheWindow, -16)
		Wlong = Wlong Or $20000 Or $80000
		Notify User32_SetWindowLong(TheWindow, -16, Wlong)


I added Or $80000 to get a system menu because adding $20000 on its own for a Minimise box doesn't work.

So now I have a blitz graphic window with a system menu and a minimise button (no maximise or resize, which is fine). One of my original questions remain: How can I tell the App to minimise if the user presses a "Boss" key? Also when I click the X, the app doesn't close. So how do I intercept the close event in my main loop so I can exit the app myself. Any help is really appreciated. Thanks


Grey Alien(Posted 2005) [#9]
OK, I found out you can minimise a window when a key is pressed like this:

1) Make sure you have a handle to your window using the FindWindow code above.
2) declare this const
Const SW_MINIMIZE = 6 ;used with ShowWindow

3) By now you must have a user32.decls file in BlitzPlus\UserLibs so add this line to it
User32_ShowWindow% (hwnd%, nCmdShow%): "ShowWindow" 

4) In your app call
User32_ShowWindow(TheWindow, SW_MINIMIZE)
where TheWindow is the handle to your window. Tada

Hope you find it useful. My game now has a boss key! Even in full-screen mode it can be done by reseting the graphics mode to use flag 2 on the end for windowed mode and then calling the minimise code from above.