Get Desktop Size

BlitzMax Forums/BlitzMax Programming/Get Desktop Size

I must be being dumb here but I don't see any easy Bmax code for get the DesktopSize on PCs, perhaps it's an API call. Anyone know? thx I presume people are using this code to work out the native screen aspect ratio.

Not my work, but here it is:

Module chaos.desktopext
ModuleInfo "Version: 1.02"
ModuleInfo "Modserver: BlitzHelp"
ModuleInfo "Author: hamZta (MacOS part) and Thorsten 'd-bug' Dietermann (Win32/Linux part)"
ModuleInfo "License: Public Domain"
ModuleInfo "Contact: d-bug@..."
ModuleInfo "Homepage: www.chaos-interactive.de"

ModuleInfo "History: 1.02 switched scope from dbug... to chaos..."
ModuleInfo "History: 1.01 added ReleaseDC to win32 version"
ModuleInfo "History: 1.00 official release (16.05.2006)"

SuperStrict

'initialize cross-platform stuff
?Win32
	Import pub.win32
	Private
	Extern
		Function ReleaseDC(hwnd:Int, hdc:Int)"Win32" 
	End Extern
	Public
?MacOS
	Import "macscreen.c"
	Private
	Extern
		Function CGDisplayCurrentMode:Byte Ptr(displayID:Byte Ptr)"MacOS"
		Function CGGetActiveDisplayList:Byte Ptr(kMaxDisplays:Int, display:Byte Ptr, numDisplays:Int Var)"MacOS"
		Function MACOS_GetWidth:Int(mode:Byte Ptr)"C"
		Function MACOS_GetHeight:Int(mode:Byte Ptr)"C"
		Function MACOS_GetBPP:Int(mode:Byte Ptr)"C"
		Function MACOS_GetHertz:Int(mode:Byte Ptr)"C"
	End Extern 
	Public
?Linux
	Import brl.graphics
?

Rem
bbdoc: Get width of current desktop
returns: The width, in pixels, of the current desktop
End Rem
Function DesktopWidth:Int ()
	Local width:Int,height:Int,depth:Int,hertz:Int
	GetDesktopMode (width, height, depth, hertz)
	Return width
End Function

Rem
bbdoc: Get height of current desktop
returns: The height, in pixels, of the current desktop
End Rem
Function DesktopHeight:Int ()
	Local width:Int,height:Int,depth:Int,hertz:Int
	GetDesktopMode (width, height, depth, hertz)
	Return height
End Function

Rem
bbdoc: Get depth of current desktop
returns: The depth, in bits, of the current desktop
End Rem
Function DesktopDepth:Int ()
	Local width:Int,height:Int,depth:Int,hertz:Int
	GetDesktopMode (width, height, depth, hertz)
	Return depth
End Function

Rem
bbdoc: Get refresh rate of current desktop
returns: The refresh rate, in frames per second, of the current desktop
End Rem
Function DesktopHertz:Int ()
	Local width:Int,height:Int,depth:Int,hertz:Int
	GetDesktopMode (width, height, depth, hertz)
	Return hertz
End Function

Rem
bbdoc: Get width, height, depth and refresh rate of the current desktop
returns: Width and height, in pixels, the depth, in bits
and the refresh rate, in frames per second of the current desktop
End Rem
Function GetDesktopMode:Int (width:Int Var, height:Int Var, depth:Int Var, hertz:Int Var)
	?win32
		Local hwnd:Int = GetDesktopWindow()
		Local hdc:Int = GetDC(hwnd)
		If hdc = Null Then Return -1
		width  = GetDeviceCaps(hdc, HORZRES)
		height = GetDeviceCaps(hdc, VERTRES)
		depth  = GetDeviceCaps(hdc, BITSPIXEL)
		hertz  = GetDeviceCaps(hdc, VREFRESH)
		ReleaseDC(hwnd,hdc)
	?MacOS
		Local display:Byte Ptr[] = New Byte Ptr[1]
		Local iMode:Byte Ptr = Null
		Local iCount:Int
		CGGetActiveDisplayList 1, display, iCount
		iMode  = CGDisplayCurrentMode(display[0])
		width  = MACOS_GetWidth(iMode)
		height = MACOS_GetHeight(iMode)
		depth  = MACOS_GetBPP(iMode)
		hertz  = MACOS_GetHertz(iMode)
	?Linux
		CountGraphicsModes()
		GetGraphicsMode (0,width,height,depth,hertz)
	?
End Function



Now to something completely different...

doesn't this just work....
Print GadgetWidth(Desktop())
Print Gadgetheight(Desktop())


Nice thanks! Is this from the code archives or here? Must've missed it.

Dunno. If I remember right this was posted in the german community.

@PantsOn: Your code needs MaxGUI, the mod works w/o it.

That looks like the desktopextension code.

Yep I use Desktop Extension for this too. All the documentation in the one I have is in German but its not that hard to figure out.

Cool I'll ask them if they mind me putting a small portion of it in my framwork.

PantsOn: I want to make the code non MaxGUI.