Window always in middle

BlitzMax Forums/BlitzMax Beginners Area/Window always in middle

Matt McFarland(Posted 2006) [#1]
Is there anyway to get the system's resolution so that the window may be displayed in the middle of the screen? I know its a simply question, and I did a search but came up with nothing!

Thanks!


po(Posted 2006) [#2]
If you're using MaxGUI:

Local window:TGadget=CreateWindow("My Window",(GadgetWidth(Desktop())-500)/2,(GadgetHeight(Desktop())-500)/2,500,500)



Grey Alien(Posted 2006) [#3]
Here's a win32 solution:

?win32
Extern "win32"
	Function GetActiveWindow%()
	Function GetDesktopWindow%()
        Function GetWindowRect%(hWnd%, lpRect: Byte Ptr)
        Function SetWindowPos%(hWnd%, after%, x%, y%, w%, h%, flags%)
End Extern
?

Type TRect
	Field L%, T%, R%, B%
End Type

' -----------------------------------------------------------------------------
' ccCentreWindow
' -----------------------------------------------------------------------------
Function ccCentreWindow()
	'Centres the current graphics window on the desktop
	?Win32
	Local hWnd% = GetActiveWindow()
	ccCentreWindowHandle(hWnd%)
	?
End Function

Function ccCentreWindowHandle(hWnd%)
	'Centres the current graphics window on the desktop
	'Pass a handle in
	?Win32
	Local desk_hWnd% = GetDesktopWindow()
	Local desk:TRect = New TRect
	Local window:TRect= New TRect

	GetWindowRect(desk_hWnd,desk) ' Get Desktop Dimensions
    'Get Window Dimensions because final window may have been resized (by BlitzMax) to fit the desktop resultion! (Grey Alien)
	GetWindowRect(hWnd,window)
	
	'Centre Window
	SetWindowPos(hWnd, -2, (desk.r / 2) - ((window.r-window.l) / 2), (desk.b / 2) - ((window.b-window.t) / 2), 0, 0, 1)
	?
End Function


Matt, haven't seen you on the forums for a while. Have you checked out my framework demo yet? Click the link in my sig, it's a SHMUP (of sorts).


Matt McFarland(Posted 2006) [#4]
Thanks alot Grey!! Yeah I've seen you have a neat fgramework thing, I haven't checked it out, but I might be doing so after I finish my current project.


Grey Alien(Posted 2006) [#5]
OK cool. Good luck with your current project.