Window Maximized?

BlitzMax Forums/BlitzMax Programming/Window Maximized?

Does anyone know how to have a BlitzMax program find out whether a window belonging to an another program is maximized or not, when you have its hWnd?

I know that I can send a ShowWindow(hWnd%,SW_Maximize) to actually maximize an existing window, but how do I find out it's current state?

After some more searching I found some BlitzPlus code by Soja on the forums that seem to return the info I need, but so far I haven't been able to convert it to BlitzMax. Can anyone see what I'm doing wrong here?

BlitzPlus:
; .lib "user32.dll"
; GetWindowPlacement%(hwnd%, pwpl*):"GetWindowPlacement"

CreateTimer(1)
w = CreateWindow("WindowPlacement Test", 100, 100, 400, 400, 0, 3)

Repeat 
	Select WaitEvent()
		Case $803 : End
		Case $4001 : wp(QueryObject(w,1))			
	End Select
Forever

Function wp(hwnd)
	wp.WindowPlacement = New WindowPlacement
	wp\size = 11 * 4
	If Not GetWindowPlacement(hwnd, wp) Then
		Notify "Failed"
	Else
		Print "Flags: " + wp\flags
		Print "ShowCmd: " + wp\showCmd
		Print "MinPos: ("+wp\x_MinPos+","+wp\y_MinPos+")"
		Print "MaxPos: ("+wp\x_MaxPos+","+wp\y_MaxPos+")"
		Print "Rect: ("+wp\leftRect+","+wp\topRect+") - ("+wp\rightRect+","+wp\bottomRect+")"
		Print "-----------"
	EndIf
End Function

Type WindowPlacement
	Field size
	Field flags
	Field showCmd
	Field x_MinPos, y_MinPos
	Field x_MaxPos, y_MaxPos
	Field leftRect, topRect, rightRect, bottomRect
End Type


My BlitzMax translation attempt: (Grabbing the hWnd of the foreground window instead, other than that it ought to be the same)
Import maxgui.drivers
Import pub.win32

w= CreateWindow ("WindowPlacement Test",100,100,400,400,0,3)

Repeat 
	Select WaitEvent()
		Case $803 ; End
		Case $4001 ; wp(pub.win32.Getforegroundwindow())			
	End Select
Forever

Function wp(hwnd)
	wp:WindowPlacement = New WindowPlacement
	wp.size = 11 * 4
	If Not GetWindowPlacement(hwnd, wp) Then
		Notify "Failed"
	Else
		Print "Flags: " + wp.flags
		Print "ShowCmd: " + wp.showCmd
		Print "MinPos: ("+wp.x_MinPos+","+wp.y_MinPos+")"
		Print "MaxPos: ("+wp.x_MaxPos+","+wp.y_MaxPos+")"
		Print "Rect: ("+wp.leftRect+","+wp.topRect+") - ("+wp.rightRect+","+wp.bottomRect+")"
		Print "-----------"
	EndIf
End Function

Type WindowPlacement
	Field size
	Field flags
	Field showCmd
	Field x_MinPos, y_MinPos
	Field x_MaxPos, y_MaxPos
	Field leftRect, topRect, rightRect, bottomRect
End Type


It fails with: Compile Error - Identifyer type does not match declared type on the line:
	wp:WindowPlacement = New WindowPlacement


Defining the variable wp as Local seemed to stop this from failing. However, you may also need to Extern the GetWindowPlacement api as it doesn't appear to be in user32.bmx. You might also want to check those WaitEvent() Select values in case they are different in BMax - when i compiled your program (after bypassing the call to GetWindowPlacement), trying to close the window did nothing and I was forced to End Task it.

Looks that that did it -- thanks!