Disable the Minimize button on a non-BMax Window?

BlitzMax Forums/BlitzMax Programming/Disable the Minimize button on a non-BMax Window?

Gabriel(Posted 2006) [#1]
I have a window HGE is creating for me, and I have the HWND to it. What I want to do is disable the Window's minimize button so that it will not minimize. I think I need to get the window styles, change them, and set them again, but google just keeps pointing me to javascript stuff for disabling minimize buttons on browser popups, which is not what I want.


assari(Posted 2006) [#2]
Gabriel, there's code in the archives on how to retrieve and set the flags http://www.blitzmax.com/codearcs/codearcs.php?code=1595


Bremer(Posted 2006) [#3]
Extern "win32"
	Function GetWindowLongA(hWnd:Long,nIndex:Int) = "GetWindowLongA@8"
	Function SetWindowLongA(hWnd:Long,nIndex:Int,uFlags:Int) = "SetWindowLongA@12"
	Function DrawMenuBar:Int(hMenu:Long)
End Extern

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

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

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:Long = GetWindowLongA( hwnd, GWL_STYLE )
	tmp = tmp | WS_MAXIMIZEBOX
	SetWindowLongA( hwnd, GWL_STYLE, tmp )
	DrawMenuBar( hwnd )
End Function



Gabriel(Posted 2006) [#4]
Thanks Zawran, but I can only get it to disable one of them. Is it not possible to do both?

I tried this :

Function DisableBothButtons(HWND:Int)
		
		Const GWL_STYLE:Int=-16
		Const NOT_WS_MINIMIZEBOX:Int=~$2000
		Const NOT_WS_MAXIMIZEBOX:Int=~$1000
		
		Local Styles:Int=GetWindowLong(HWND, GWL_STYLE)
		Styles=Styles & NOT_WS_MAXIMIZEBOX
		Styles=Styles & NOT_WS_MINIMIZEBOX
		SetWindowLong(HWND,GWL_STYLE,Styles)
		DrawMenuBar(HWND)
		
	End Function



Which is my conversion of this ( Delphi )

procedure TForm1.FormCreate(Sender: TObject);
var
  l: DWORD;
begin
  l := GetWindowLong(Self.Handle, GWL_STYLE);
  l := l and not (WS_MINIMIZEBOX);
  l := l and not (WS_MAXIMIZEBOX);
  l := SetWindowLong(Self.Handle, GWL_STYLE, l);
end;


But either I've got the bitwise operators wrong or BMax is not generating the right result for a bitwise Not.


Yan(Posted 2006) [#5]
Your constants are wrong...
Const NOT_WS_MINIMIZEBOX:Int=~$20000
Const NOT_WS_MAXIMIZEBOX:Int=~$10000
Or simply...
'Import Pub.Win32

Function DisableBothButtons(HWND:Int)
  Local Styles:Int = GetWindowLongA(HWND, GWL_STYLE)
  Styles :& ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
  SetWindowLongA(HWND, GWL_STYLE, Styles)
  DrawMenuBar(HWND)		
End Function



Gabriel(Posted 2006) [#6]
Doh! I can't believe it was just that I missed a zero off the constants. Clearly I should change my name to Marvin the Myopic Martian or something for missing that one.

Thanks man.