Calc height of title bar or client area top left?

BlitzMax Forums/BlitzMax Programming/Calc height of title bar or client area top left?

Grey Alien(Posted 2006) [#1]
Hiya. Does anyone know how to calc the hieght of the title bar. I ask because it can vary. For example XP Theme is not the same as Windows Classic Theme + bigger ones can be made by fiddling with the settings.

I'm keen to work it out because I want to know where the top left drawable coordinate is relative to the desktop. The problem is that GetWindowRect returns the top left of the window (meaning the top left of the title bar) and I need the top left of the client area (the drawable zone). So I need to add on a few pixels to the X coord to account for the border and a certain amount for the title bar, but that amount can vary a lot.

Any ideas?

Much neater is if I can just find out where a coordinate on the graphics window (e.g 0,0) is relative to the desktop top left.

None of this would be needed if BlitMax was able to record a mouse coordinate outside of it's own window i.e. negative or greater than the window width/height. I'm not really into hacking modules for this type of fix though.

Thanks loads in advance.


VIP3R(Posted 2006) [#2]
If you get stuck for options, the User32 API function 'GetWindowInfo' will give you the client area info you need. Using this info you can calculate the X and Y coords / dimensions of the client area.

Obviously it will only work on Win32 platforms.


Grey Alien(Posted 2006) [#3]
yep I was just thinking that If I know the window height I can subtract the client height and get the titlebar height (but also need to take into account the bottom border). I'll think on this some more. Anyone have a ready made Max implmentation of GetWindowInfo?


Suco-X(Posted 2006) [#4]
Hi.
Look at GetSystemMetrics if you need extra Windows information.
Mfg Suco


Grey Alien(Posted 2006) [#5]
Thanks GetSystemMetrics will tell me the border width (which I've found out can be altered in themes) but not the title bar height.

'GetWindowInfo' looks like it will give a rect of the client area, whether that's relative to the desktop or the window it's in is another thing ... I'll let you know.


Suco-X(Posted 2006) [#6]
Hi

Const SM_CYCAPTION	= 4

Print GetSystemMetrics(SM_CYCAPTION)


Isn't that the height of the title bar?
Mfg Sucp


Grey Alien(Posted 2006) [#7]
yes it is thanks, doh, I searched for keyword Title not "Caption" in my delphi Win32 help and Title Bar wasn't mentioned in it.

So to work out the top left coord of the client area, I must get the window post and add on window border (from GetSystemMetrics and then the "Caption" height.

Before I try that, I'm halfway through trying GetWindowInfo to see if the ClientRect is any good.


TartanTangerine (was Indiepath)(Posted 2006) [#8]
Grey, is this for your Framework? You might want to consider cross-platform support for all these neat little tweaks you are making.


Grey Alien(Posted 2006) [#9]
Indiepath: Sure I'll switch all thisstuff off on the Max/Linux version and have to find out equivalent stuff for those platforms (which WON'T be easy) or leave the tweaks out altogeher.

Anyway I'm having trouble with this:

Strict

Type TWindowInfo
    Field cbSize
    Field rcWindow:TRect
    Field rcClient:TRect
    Field dwStyle
    Field dwExStyle
    Field dwWindowStatus 
    Field cxWindowBorders
    Field cyWindowBorders
    Field atomWindowType:Short 'Research shows an Atom to be a 16-bit value (I hope)
    Field wCreatorVersion:Short
End Type

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

Extern "win32"
	Function GetWindowInfo(hWnd%, WindowInfo: Byte Ptr)       
End Extern

Function ccGetWindowInfo:TWindowInfo(hWnd%)
	Local wi:TWindowInfo = New TWindowInfo
	wi.cbSize = SizeOf(wi)
	wi.rcWindow = New TRect
	wi.rcClient = New TRect
	GetWindowInfo(hwnd,wi)	
	Return wi
End Function       

Graphics 800,600,0

Local wi:TWindowInfo = ccGetWindowInfo(GetActiveWindow()) 
Cls
DrawText wi.rcwindow.l,0,0
Flip
WaitKey

I getting a MAV on the drawtext line. Clearly GetWindowInfo is just overwriting it with junk or something. Any ideas?


Grey Alien(Posted 2006) [#10]
WOO, Eureka. I've done it. It didn't need pointers to rects but rather the 4 32-bit integers that make up a Rect!

Check this code out, it displays the window coords plus height and width and the client area coords plus height and width. Very useful!

Strict

Type TWindowInfo
    Field cbSize
    Field wl,wt,wr,wb 'need to inline the TRect as 4xIntegers
	Field cl,ct,cr,cb 'need to inline the TRect as 4xIntegers
'    Field rcWindow:TRect
'    Field rcClient:TRect
    Field dwStyle
    Field dwExStyle
    Field dwWindowStatus 
    Field cxWindowBorders
    Field cyWindowBorders
    Field atomWindowType:Short 'Research shows an Atom to be a 16-bit value (I hope)
    Field wCreatorVersion:Short
End Type

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

Extern "win32"
	Function GetWindowInfo(hWnd%, WindowInfo: Byte Ptr)       
End Extern

Function ccGetWindowInfo:TWindowInfo(hWnd%)
	Local wi:TWindowInfo = New TWindowInfo
	wi.cbSize = SizeOf(wi)
'	wi.rcWindow = New TRect
'	wi.rcClient = New TRect
	GetWindowInfo(hwnd,wi)
	Return wi
End Function       

Graphics 800,600,0

Local wi:TWindowInfo = ccGetWindowInfo(GetActiveWindow()) 
Cls
DrawText wi.wl,0,0
DrawText wi.wr,0,20
DrawText wi.wt,0,40
DrawText wi.wb,0,60
DrawText "Window Width = "+(wi.wr-wi.wl),0,80
DrawText "Window Height = "+(wi.wb-wi.wt),0,100

DrawText wi.cl,0,200
DrawText wi.cr,0,220
DrawText wi.ct,0,240
DrawText wi.cb,0,260
DrawText "Client Width = "+(wi.cr-wi.cl),0,280
DrawText "Client Height = "+(wi.cb-wi.ct),0,300

Flip
WaitKey



SebHoll(Posted 2006) [#11]
If the window just has a titlebar (and no status bar etc.) then you could use the following code:
Strict

Local gadWindow:TGadget = CreateWindow("Test Window",400,400,400,300,Null,WINDOW_TITLEBAR)

Local tmpGadHeight:Int = GadgetHeight(gadWindow)
Local tmpCliHeight:Int = ClientHeight(gadWindow)

Local tmpTitlebar:Int = tmpGadHeight - tmpCliHeight

Notify("Titlebar (+ bottom border): " + tmpTitlebar)

Repeat


	Select WaitEvent()
	
		Case EVENT_WINDOWCLOSE;End

	End Select

Forever


End
It should be multi-platform as it just uses native MaxGUI commands. The value given is the value of the titlebar and the bottom border.


Just a thought, though I'm not sure it is what you are looking for.



Seb


Grey Alien(Posted 2006) [#12]
useful thanks :-) I might have to use that for the Mac/Linux but right now I want BMax users to be able to use this code even if they don't have the MaxGUI module.


TartanTangerine (was Indiepath)(Posted 2006) [#13]
I think I'm missing the point, what is this for?


Robert Cummings(Posted 2006) [#14]
Yep - whats it for?


Grey Alien(Posted 2006) [#15]
So I can smoothly draw the custom mouse pointer at negative coordinates as it slides left or up out of the game window. Not possible with MouseX() and MouseY() due to them never going <0. Also it prevents a "dead" mouse cursor from being left in the window if you move the mouse out quickly.

See it in action here:

http://www.blitzbasic.com/Community/posts.php?topic=58836

It's done now (the Game Framework) now more analy retentive fiddly bits, I can just get on with the next game. One day I'll have to do all this crap again for Mac compatibility, and I might even have to take some of it out if it gets fixed/altered in future BMax releases. But at least I have a list of things to test each release now.