Re: Caption Height

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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


.



Relevant Pages

  • Re: How would you do it
    ... Create the window large enough to hold a border drawing. ... Then Invalidate() ... Alternatively, you can use XOR/XORNOT or something like that to draw the border, so each ...
    (microsoft.public.vc.mfc)
  • JWindow resizing flicker
    ... facing problem with flicker during the resize (I validate the window ... /* Set a nice border - try to use the internal frame border ... private class ResizeListener extends MouseAdapter ... int width = getWidth; ...
    (comp.lang.java.gui)
  • Re: Text aus Dialogboxen?
    ... Zumindest bei vielen Dialogen kannst du einfach mit der Maus den Text ... You have selected to show a window without its border. ... Window Operations Menu keyboard shortcut. ...
    (de.comp.os.unix.apps.kde)
  • Re: Mouse leave for windows form which has some controls not firing as desired
    ... you move the mouse out of your client area onto the window border the ... so the test for being outside the window fails. ... don't get another event because the mouse has already left the client area. ... Although I know how to do both of these from a pure Win32 API application ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Mouse leave for windows form which has some controls not firing as desired
    ... you move the mouse out of your client area onto the window border the ... so the test for being outside the window fails. ... don't get another event because the mouse has already left the client area. ... Although I know how to do both of these from a pure Win32 API application ...
    (microsoft.public.dotnet.languages.csharp)