Minimise Button with windowed app?

BlitzMax Forums/BlitzMax Programming/Minimise Button with windowed app?

Grisu(Posted 2006) [#1]
Hello!

Is it possible to give a windowed app a minimise button. E.g. "Graphics 800,600,0" and to check its current state.

Thanks.


Bremer(Posted 2006) [#2]
I am using functions like these:

Extern "win32"
	Function GetActiveWindow()
	Function GetWindowLongA(hWnd%, nIndex%) = "GetWindowLongA@8"
	Function SetWindowLongA(hWnd%, nIndex%, uFlags%) = "SetWindowLongA@12"
	Function DrawMenuBar%(hMenu%)
End Extern

Const WS_MAXIMIZEBOX:Long = $10000
Const WS_MINIMIZEBOX:Long = $20000
Const GWL_STYLE:Int = -16

Function disableMaximize(hWnd:Long)
	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
	Local tmp2:Long = tmp And WS_MAXIMIZEBOX
	tmp = tmp - tmp2
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function

Function enableMaximize(hWnd:Long)
	Local tmp:Int = GetWindowLongA( hWnd, GWL_STYLE )
	tmp = tmp | WS_MAXIMIZEBOX
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function

Function disableMinimize(hWnd:Long)
	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
	Local tmp2:Long = tmp And WS_MINIMIZEBOX
	tmp = tmp - tmp2
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function

Function enableMinimize(hWnd:Long)
	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
	tmp = tmp | WS_MINIMIZEBOX
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function

' example
local handle:long = GetActiveWindow()
enableMinimize( handle )


[edit]
I haven't tried checking what the status of them is before changing them but I am thinking that if you do a "GetWindowLongA( hWnd, GWL_STYLE )" and then check against those bits that the conts contain, it should tell you whether or not they are enabled or disabled. Unless you mean check whether or not the application is minimized or not, then that would be something with the focus of the application. I am quite new to all this winApi stuff, so perhaps someone else got some code for that.


taxlerendiosk(Posted 2006) [#3]
There's a better way to get the Hwnd of the app window (not GadgetQuery, it doesn't involve MaxGUI)... but I've forgotten it.


Bremer(Posted 2006) [#4]
What I posted shouldn't need MaxGUI that I know of.


taxlerendiosk(Posted 2006) [#5]
No, no, you misunderstand me. I meant that there's an alternative to GetActiveWindow that is set when an application window is opened. Still can't find it though.


Grisu(Posted 2006) [#6]
Would it be easier to create a window with maxgui and simply draw the contents to it. Without using the gui framework at all? - This winapi stuff always hurts... :(


Grisu(Posted 2006) [#7]
Graphics 800,600,0

Extern "win32"
	Function GetActiveWindow()
	Function GetWindowLongA(hWnd%, nIndex%) = "GetWindowLongA@8"
	Function SetWindowLongA(hWnd%, nIndex%, uFlags%) = "SetWindowLongA@12"
	Function DrawMenuBar%(hMenu%)
End Extern

Const WS_MAXIMIZEBOX:Long = $10000
Const WS_MINIMIZEBOX:Long = $20000
Const GWL_STYLE:Int = -16

'Function disableMaximize(hWnd:Long)
'	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
'	Local tmp2:Long = tmp And WS_MAXIMIZEBOX
'	tmp = tmp - tmp2
'	SetWindowLongA( hWnd, GWL_STYLE, tmp )
'	DrawMenuBar( hWnd )
'End Function

Function enableMaximize(hWnd:Long)
	Local tmp:Int = GetWindowLongA( hWnd, GWL_STYLE )
	tmp = tmp | WS_MAXIMIZEBOX
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function

'Function disableMinimize(hWnd:Long)
'	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
'	Local tmp2:Long = tmp And WS_MINIMIZEBOX
'	tmp = tmp - tmp2
'	SetWindowLongA( hWnd, GWL_STYLE, tmp )
'	DrawMenuBar( hWnd )
'End Function

Function enableMinimize(hWnd:Long)
	Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE )
	tmp = tmp | WS_MINIMIZEBOX
	SetWindowLongA( hWnd, GWL_STYLE, tmp )
	DrawMenuBar( hWnd )
End Function

' example
Local handle:Long = GetActiveWindow()
 enableMinimize( handle )
 enableMaximize( handle )

Repeat
  Cls 
  SetColor 255,255,255
  DrawText "Minimise Me... :)", 20,20
  Flip 
Until KeyHit(KEY_ESCAPE) Or AppTerminate()


Is there a way to check the enabled Maximise button?
So my app can go to fullscreen in that case?


Bremer(Posted 2006) [#8]
I have just spent a lot of time with google and haven't found anything that describes how to capture the event that someone clicks on the maximize button. By using the pollevent command from the event module, it looks like the minimize sends a 257 value when its clicked, and there is a 258 value when the window is restored. But clicking on the maximize buttons doesn't trigger any values at all.


Grisu(Posted 2006) [#9]
I think the event is WS_MAXIMIZE / WS_MINIMISE, I goggled myself... nothing usefull...

At least I have solved the minimise issue.
It can be checked in bmx via "appsuspended".

Thanks for your help!


Bremer(Posted 2006) [#10]
You're welcome. I am just only getting started on winapi stuff, and it seems like there is a ton of information that one needs to know, but one step at a time and I'll get there :) Glad you could use it.


N(Posted 2006) [#11]
Best I could find: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/usinghooks.asp


Grisu(Posted 2006) [#12]
I know of getting hugged sometimes, but windows hooks are new to me... ;)


N(Posted 2006) [#13]
Now would be a good time to learn.


Grisu(Posted 2006) [#14]
My IQ is too low for that. :/