How do you calculate the title bar height in VB6?

I am trying to display one form relative to a button on a control below it.

But Button.top refers to the title of the bottom form, and the top form will relate to the screen.

So, to compensate for this, I need now how high the headline is.

I used Form.height-Form.ScalehHeight, but ScaleHeight does not include the title bar or , therefore, Scaleheight is slightly overpriced.

Does anyone know how to calculate the height of only the title bar?

+7
vb6
source share
6 answers

Cross it out:

(Form.height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth) / 2 
+9
source share

You need to use the GetSystemMetrics API GetSystemMetrics to get the height of the header.

 Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long Private Const SM_CYCAPTION = 4 Property Get TitleBarHeight() as Long TitleBarHeight = GetSystemMetrics(SM_CYCAPTION) End Property 

Note. This will return the height in pixels. If you need twips, you have to convert using the ScaleY form ScaleY , for example: Me.ScaleY(TitleBarHeight(), vbPixels, vbTwips)

+9
source share

The answer "Recursive" above is not entirely correct. He subtracts the width of the border twice - there is a border on the left and on the right!

We get the best results:

 (Form.Height-Form.ScaleHeight) - (Form.Width-Form.ScaleWidth)/2 
+3
source share
 ' For completeness: Public Const SM_CYCAPTION = 4 Public Const SM_CYBORDER = 6 Public Const SM_CYFRAME = 33 ' in Pixels Property Get NonClinetHeight() FrameH = GetSystemMetrics(SM_CYFRAME) ' Total height, Top + Bottom CaptionH = GetSystemMetrics(SM_CYCAPTION) BorderH = GetSystemMetrics(SM_CYBORDER) ' Border around Client area NonClinetHeight = FrameH + CaptionH + (BorderH * 2) End Property 
+3
source share

You will probably need to call the Win32 API call to GetSystemMetrics ()

+1
source share

You can use the ClientToScreen() API function to convert a point from client coordinates to screen coordinates:

 Dim Position As Point Position.x = 0 Position.y = 0 ClientToScreen Me.hWnd, Position FormTop = Position.y 

If you want to skip this and go straight to the button, you can use the button position (in pixels):

 Position.x = This.ScaleX(Button.Left, this.ScaleMode, vbPixels) Position.Y = This.ScaleY(Button.Top, this.ScaleMode, vbPixels) ... 

Or just set the position of the buttons using GetWindowRect()

 Dim Position2 As Rect GetClientRect Button.hWnd, Position2 Position.x = Position2.left Position.y = Position2.top ... 
+1
source share

All Articles