Re: Caption Height
- From: "expvb" <nobody@xxxxxxx>
- Date: Wed, 14 Jan 2009 19:45:14 -0500
"David Youngblood" <dwy@xxxxxxxxx> wrote in message
news:OpS2rLqdJHA.4684@xxxxxxxxxxxxxxxxxxxxxxx
26, and yes I have considered that. But that assumes a border at the top
and bottom of the form (width - scalewidth = 2 times frame thickness).
That doesn't appear to be the case for a themed window. The caption has
rounded corners so drawing a top border will not work. Also, looking at
the themed window part ID's there are parts for left frame, right frame
and bottom frame, but no top frame part.
That might be what I end up doing, adding caption height + 1 frame width.
For the not themed window, I am already subtracting border width (1 pixel)
from the value returned by GetSystemMetrics. I'm just trying to find
"correct" formula, if one exists.
This code asks Windows what is the top left (0,0) corner positions in pixels
relative to the screen, then subtract the result from the upper left corner
of the window, including the title bar. This gets the actual border size. In
my case with XP default theme, your code printed the following(With
BoderStyle of Form1 set to the default "2 - Sizable"):
Using GetThemePartSize, caption height = 29
Using GetSystemMetrics, caption height = 26
Larry's code printed the following:
Border: 60 (Twips) = 4 (Pixels)
TitleBar: 390 (Twips) = 26 (Pixels)
Strangely I expected Larry's method to work and it does when I converted
everything to pixels first as shown here:
Private Sub Command1_Click()
Dim bdr&, cap&
Me.ScaleMode = vbPixels
bdr = ((Me.Width / Screen.TwipsPerPixelX) - Me.ScaleWidth) / 2
cap = Me.Height / Screen.TwipsPerPixelY - Me.ScaleHeight - bdr
Debug.Print bdr, cap
End Sub
This prints:
4 30
My code printed the following:
Border = 4
Titlebar = 30
Don't ask me why Windows does this, or what's the correct constants to use
as I don't know. My method calculates the actual border, regardless of the
type of window and BorderStyle, it works for instance with tool windows and
PictureBoxes.
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, _
lpRect As RECT) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, _
lpPoint As POINTAPI) As Long
Private Function GetWindowBordersSize(ByVal hWnd As Long) As POINTAPI
Dim pntWindowBordersSize As POINTAPI
Dim rec As RECT
' Get the top left (0,0) corner position
' in pixels relative to the screen
pntWindowBordersSize.x = 0
pntWindowBordersSize.y = 0
ClientToScreen hWnd, pntWindowBordersSize
' Get the window dimensions, including the titlebar
GetWindowRect hWnd, rec
' Subtract the top left corner of the client from
' the top left corner of the window
pntWindowBordersSize.x = pntWindowBordersSize.x - rec.Left
pntWindowBordersSize.y = pntWindowBordersSize.y - rec.Top
GetWindowBordersSize = pntWindowBordersSize
End Function
Private Sub Command1_Click()
Dim pntWindowBordersSize As POINTAPI
pntWindowBordersSize = GetWindowBordersSize(Me.hWnd)
Debug.Print "Border = " & pntWindowBordersSize.x
Debug.Print "Titlebar = " & pntWindowBordersSize.y
End Sub
.
- Follow-Ups:
- Re: Caption Height
- From: David Youngblood
- Re: Caption Height
- References:
- Caption Height
- From: David Youngblood
- Re: Caption Height
- From: Larry Serflaten
- Re: Caption Height
- From: David Youngblood
- Caption Height
- Prev by Date: Re: Caption Height
- Next by Date: Re: Caption Height
- Previous by thread: Re: Caption Height
- Next by thread: Re: Caption Height
- Index(es):
Relevant Pages
|