How do I get the size of form borders and title bar on a form

How do I get the size of form borders and title bar on a form

Post by Guy Bradle » Sat, 10 Nov 2001 12:08:12



Hi,

I need to find out the size of the borders on a form.  If someone
changes their display settings from small fonts to big fonts the
thickness changes in the borders around the form and I have to detect
this in my app to make some adjustments of some controls.  While we are
here, is there also a way to get the height and width of the title bar?

Thanks for your time,

Guy

 
 
 

How do I get the size of form borders and title bar on a form

Post by Rocky Clar » Sat, 10 Nov 2001 22:01:30


If you adjust your controls using ScaleWidth and ScaleHeight, the size of
the borders won't matter. ScaleWidth/ScaleHeight are based on the client
area of the form (the inside minus the borders, titlebar, etc.). If you want
to find out when the border changes, just check for a change in
ScaleWidth/ScaleHeight in the Paint event. Whenever a system property
changes that would affect the size, style, color, etc of your form, Windows
will send a WM_PAINT event to update the form.

Example:
Private Sub Form_Paint()

Static fScaleWidth  As Single
Static fScaleHeight As Single

    If Me.ScaleWidth <> fScaleWidth Or _
      Me.ScaleHeight <> fScaleHeight Then
        fScaleWidth = Me.ScaleWidth
        fScaleHeight = Me.ScaleHeight

        'Note: Your resize function should be based
        'on the ScaleWidth/ScaleHeight of the Form,
        'instead of the Width/Height.
        Call ResizeControls
    End If

End Sub

Note: If your Form.AutoRedraw = True then you will need to find another way
(subclassing or maybe a timer(yuk) control), since the Paint event will not
fire while AutoRedraw is on.

If you still need the border width/height, the following code will return
them in twips:

    BorderWidth = Me.Width - _
      Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbTwips)
    BorderHeight = Me.Height - _
      Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, vbTwips)

The Titlebar height can be calculated as follows:
    TitlebarHeight = BorderHeight - BorderWidth

Note: There are API functions to return these figures, but this is just as
easy and you won't need any API declares.

Hope this helps,

Rocky


Quote:> Hi,

> I need to find out the size of the borders on a form.  If someone
> changes their display settings from small fonts to big fonts the
> thickness changes in the borders around the form and I have to detect
> this in my app to make some adjustments of some controls.  While we are
> here, is there also a way to get the height and width of the title bar?

> Thanks for your time,

> Guy


 
 
 

How do I get the size of form borders and title bar on a form

Post by Andy Stewartso » Sat, 10 Nov 2001 23:59:14


I think this is what you are after

use the API  GetSystemMetrics(value)

    Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex
As Long) As Long

    Public Const SM_CYMENU                      As Long = 15
    Public Const SM_CXMIN                       As Long = 28
    Public Const SM_CYMIN                       As Long = 29
    Public Const SM_CXBORDER                    As Long = 5
    Public Const SM_CYBORDER                    As Long = 6
    Public Const SM_CXDLGFRAME                  As Long = 7
    Public Const SM_CYDLGFRAME                  As Long = 8
    Public Const SM_CXFIXEDFRAME                As Long = SM_CXDLGFRAME
    Public Const SM_CYFIXEDFRAME                As Long = SM_CYDLGFRAME

 the constants are

SM_CXBORDER and SM_CYBORDER
      Width and height, in pixels, of a window border. This is
equivalent to
      the SM_CXEDGE value for windows with the 3-D look.

SM_CXFIXEDFRAME and SM_CYFIXEDFRAME
     Thickness, in pixels, of the frame around the perimeter of a window
that
     has a caption but is not sizable. SM_CXFIXEDFRAME is the width of
the
     horizontal border and SM_CYFIXEDFRAME is the height of the vertical
border.  

SM_CXMIN and SM_CYMIN
     Minimum width and height, in pixels, of a window.

SM_CYMENU
    Height, in pixels, of a single-line menu bar.

there is a whole load more in the help file but these will hopefully
give you the dimensions you want

Andy Stewartson

+------------------------------+---------------------------------------+
 Andy Stewartson,              | Tel: +44 1634 844400 ext. 4562
 Principal Mechanical Engineer | Fax: +44 1634 816360
 Mechanical Design Engineering |
 Mission Systems Division      |

 Rochester, ME1 2XX            |

 
 
 

How do I get the size of form borders and title bar on a form

Post by Guy Bradle » Mon, 12 Nov 2001 01:19:11


Thanks.  I tried everything using the GetSystemMetrics function and I can
not get the
thickness of the border.  All I get is 4.  If I remove the titlebar from the
form I can
visually see the thickness of the border get smaller.  I try getting the
value and I get
4.  Bring back the titlebar and the thickness gets bigger.  I try getting
the value and I
get 4.  I need the thickness.  I hope someone can shed some light.

Thanks.

Guy


> I think this is what you are after

> use the API  GetSystemMetrics(value)

>     Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex
> As Long) As Long

>     Public Const SM_CYMENU                      As Long = 15
>     Public Const SM_CXMIN                       As Long = 28
>     Public Const SM_CYMIN                       As Long = 29
>     Public Const SM_CXBORDER                    As Long = 5
>     Public Const SM_CYBORDER                    As Long = 6
>     Public Const SM_CXDLGFRAME                  As Long = 7
>     Public Const SM_CYDLGFRAME                  As Long = 8
>     Public Const SM_CXFIXEDFRAME                As Long = SM_CXDLGFRAME
>     Public Const SM_CYFIXEDFRAME                As Long = SM_CYDLGFRAME

>  the constants are

> SM_CXBORDER and SM_CYBORDER
>       Width and height, in pixels, of a window border. This is
> equivalent to
>       the SM_CXEDGE value for windows with the 3-D look.

> SM_CXFIXEDFRAME and SM_CYFIXEDFRAME
>      Thickness, in pixels, of the frame around the perimeter of a window
> that
>      has a caption but is not sizable. SM_CXFIXEDFRAME is the width of
> the
>      horizontal border and SM_CYFIXEDFRAME is the height of the vertical
> border.

> SM_CXMIN and SM_CYMIN
>      Minimum width and height, in pixels, of a window.

> SM_CYMENU
>     Height, in pixels, of a single-line menu bar.

> there is a whole load more in the help file but these will hopefully
> give you the dimensions you want

> Andy Stewartson

> +------------------------------+---------------------------------------+
>  Andy Stewartson,              | Tel: +44 1634 844400 ext. 4562
>  Principal Mechanical Engineer | Fax: +44 1634 816360
>  Mechanical Design Engineering |
>  Mission Systems Division      |

>  Rochester, ME1 2XX            |

 
 
 

How do I get the size of form borders and title bar on a form

Post by Guy Bradle » Mon, 12 Nov 2001 01:19:34


Thanks, but I am using a MDI form which does not have ScaleWidth and
ScaleHeight.  I tried everything using the GetSystemMetrics function and I can
not
get the thickness of the border.  All I get is 4.  If I remove the titlebar from
the form I
can visually see the thickness of the border get smaller.  I try getting the
value and I
get 4.  Bring back the titlebar and the thickness gets bigger.  I try getting
the value
and I get 4.  I need the thickness.  I hope someone can shed some light.

Thanks.

Guy


> If you adjust your controls using ScaleWidth and ScaleHeight, the size of
> the borders won't matter. ScaleWidth/ScaleHeight are based on the client
> area of the form (the inside minus the borders, titlebar, etc.). If you want
> to find out when the border changes, just check for a change in
> ScaleWidth/ScaleHeight in the Paint event. Whenever a system property
> changes that would affect the size, style, color, etc of your form, Windows
> will send a WM_PAINT event to update the form.

> Example:
> Private Sub Form_Paint()

> Static fScaleWidth  As Single
> Static fScaleHeight As Single

>     If Me.ScaleWidth <> fScaleWidth Or _
>       Me.ScaleHeight <> fScaleHeight Then
>         fScaleWidth = Me.ScaleWidth
>         fScaleHeight = Me.ScaleHeight

>         'Note: Your resize function should be based
>         'on the ScaleWidth/ScaleHeight of the Form,
>         'instead of the Width/Height.
>         Call ResizeControls
>     End If

> End Sub

> Note: If your Form.AutoRedraw = True then you will need to find another way
> (subclassing or maybe a timer(yuk) control), since the Paint event will not
> fire while AutoRedraw is on.

> If you still need the border width/height, the following code will return
> them in twips:

>     BorderWidth = Me.Width - _
>       Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbTwips)
>     BorderHeight = Me.Height - _
>       Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, vbTwips)

> The Titlebar height can be calculated as follows:
>     TitlebarHeight = BorderHeight - BorderWidth

> Note: There are API functions to return these figures, but this is just as
> easy and you won't need any API declares.

> Hope this helps,

> Rocky



> > Hi,

> > I need to find out the size of the borders on a form.  If someone
> > changes their display settings from small fonts to big fonts the
> > thickness changes in the borders around the form and I have to detect
> > this in my app to make some adjustments of some controls.  While we are
> > here, is there also a way to get the height and width of the title bar?

> > Thanks for your time,

> > Guy

 
 
 

How do I get the size of form borders and title bar on a form

Post by Guy Bradle » Mon, 12 Nov 2001 01:29:01


Hi again,

Doesn't GetSystemMetrics get system info?  How do I pass a handle to it of
the window I need the border size from?

Thanks,

Guy


> I think this is what you are after

> use the API  GetSystemMetrics(value)

>     Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex
> As Long) As Long

>     Public Const SM_CYMENU                      As Long = 15
>     Public Const SM_CXMIN                       As Long = 28
>     Public Const SM_CYMIN                       As Long = 29
>     Public Const SM_CXBORDER                    As Long = 5
>     Public Const SM_CYBORDER                    As Long = 6
>     Public Const SM_CXDLGFRAME                  As Long = 7
>     Public Const SM_CYDLGFRAME                  As Long = 8
>     Public Const SM_CXFIXEDFRAME                As Long = SM_CXDLGFRAME
>     Public Const SM_CYFIXEDFRAME                As Long = SM_CYDLGFRAME

>  the constants are

> SM_CXBORDER and SM_CYBORDER
>       Width and height, in pixels, of a window border. This is
> equivalent to
>       the SM_CXEDGE value for windows with the 3-D look.

> SM_CXFIXEDFRAME and SM_CYFIXEDFRAME
>      Thickness, in pixels, of the frame around the perimeter of a window
> that
>      has a caption but is not sizable. SM_CXFIXEDFRAME is the width of
> the
>      horizontal border and SM_CYFIXEDFRAME is the height of the vertical
> border.

> SM_CXMIN and SM_CYMIN
>      Minimum width and height, in pixels, of a window.

> SM_CYMENU
>     Height, in pixels, of a single-line menu bar.

> there is a whole load more in the help file but these will hopefully
> give you the dimensions you want

> Andy Stewartson

> +------------------------------+---------------------------------------+
>  Andy Stewartson,              | Tel: +44 1634 844400 ext. 4562
>  Principal Mechanical Engineer | Fax: +44 1634 816360
>  Mechanical Design Engineering |
>  Mission Systems Division      |

>  Rochester, ME1 2XX            |

 
 
 

How do I get the size of form borders and title bar on a form

Post by Rocky Clar » Mon, 12 Nov 2001 02:52:45


Well then try this:

Private Type Rect
    Left    As Long
    Top     As Long
    Right   As Long
    Bottom  As Long
End Type

Private Declare Function GetClientRect Lib "user32" _
    (ByVal hWnd As Long, lpRect As Rect) As Long

Private Sub MDIForm_Resize()

Dim rcBox As Rect

    Call GetClientRect(Me.hWnd, rcBox)

    'GetClientRect returns rcBox in pixels.
    'Left, Top are always 0, 0.
    Debug.Print "ScaleWidth = " & rcBox.Right _
        & "; ScaleHeight = " & rcBox.Bottom

End Sub

Rocky


> Thanks, but I am using a MDI form which does not have ScaleWidth and
> ScaleHeight.  I tried everything using the GetSystemMetrics function and I
can
> not
> get the thickness of the border.  All I get is 4.  If I remove the
titlebar from
> the form I
> can visually see the thickness of the border get smaller.  I try getting
the
> value and I
> get 4.  Bring back the titlebar and the thickness gets bigger.  I try
getting
> the value
> and I get 4.  I need the thickness.  I hope someone can shed some light.

> Thanks.

> Guy


> > If you adjust your controls using ScaleWidth and ScaleHeight, the size
of
> > the borders won't matter. ScaleWidth/ScaleHeight are based on the client
> > area of the form (the inside minus the borders, titlebar, etc.). If you
want
> > to find out when the border changes, just check for a change in
> > ScaleWidth/ScaleHeight in the Paint event. Whenever a system property
> > changes that would affect the size, style, color, etc of your form,
Windows
> > will send a WM_PAINT event to update the form.

> > Example:
> > Private Sub Form_Paint()

> > Static fScaleWidth  As Single
> > Static fScaleHeight As Single

> >     If Me.ScaleWidth <> fScaleWidth Or _
> >       Me.ScaleHeight <> fScaleHeight Then
> >         fScaleWidth = Me.ScaleWidth
> >         fScaleHeight = Me.ScaleHeight

> >         'Note: Your resize function should be based
> >         'on the ScaleWidth/ScaleHeight of the Form,
> >         'instead of the Width/Height.
> >         Call ResizeControls
> >     End If

> > End Sub

> > Note: If your Form.AutoRedraw = True then you will need to find another
way
> > (subclassing or maybe a timer(yuk) control), since the Paint event will
not
> > fire while AutoRedraw is on.

> > If you still need the border width/height, the following code will
return
> > them in twips:

> >     BorderWidth = Me.Width - _
> >       Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbTwips)
> >     BorderHeight = Me.Height - _
> >       Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, vbTwips)

> > The Titlebar height can be calculated as follows:
> >     TitlebarHeight = BorderHeight - BorderWidth

> > Note: There are API functions to return these figures, but this is just
as
> > easy and you won't need any API declares.

> > Hope this helps,

> > Rocky



> > > Hi,

> > > I need to find out the size of the borders on a form.  If someone
> > > changes their display settings from small fonts to big fonts the
> > > thickness changes in the borders around the form and I have to detect
> > > this in my app to make some adjustments of some controls.  While we
are
> > > here, is there also a way to get the height and width of the title
bar?

> > > Thanks for your time,

> > > Guy

 
 
 

How do I get the size of form borders and title bar on a form

Post by Billy Jo » Mon, 12 Nov 2001 09:27:11


Reading the rest of this thread, I gather you already have the code you need
to resize controls and are off-put only by the user's display font size
setting.
If you place constants in your code for your design dimensions and divide by
what you find on Form_Load to be the user's settings, you can could simply
use the result as a factor to your positioning and sizing algorithm.

I actually use this:
Const designTwips = 12            'I happen to use large fonts
Const designScreenWidth = 1600 * designTwips
Dim designFactor As Single
' To retain relative form size to screen size use this formula
  designFactor = Screen.Width / designScreenWidth
' To merely compensate for Large/Small font setting use this formula
  designFactor = Screen.TwipsPerPixelX / designTwips
'use one or the other

HTH,
Billy Joe


Quote:> Hi,

> I need to find out the size of the borders on a form.  If someone
> changes their display settings from small fonts to big fonts the
> thickness changes in the borders around the form and I have to detect
> this in my app to make some adjustments of some controls.  While we are
> here, is there also a way to get the height and width of the title bar?

> Thanks for your time,

> Guy

 
 
 

How do I get the size of form borders and title bar on a form

Post by Guy Bradle » Mon, 12 Nov 2001 10:05:47


That did it, thanks.

> Well then try this:

> Private Type Rect
>     Left    As Long
>     Top     As Long
>     Right   As Long
>     Bottom  As Long
> End Type

> Private Declare Function GetClientRect Lib "user32" _
>     (ByVal hWnd As Long, lpRect As Rect) As Long

> Private Sub MDIForm_Resize()

> Dim rcBox As Rect

>     Call GetClientRect(Me.hWnd, rcBox)

>     'GetClientRect returns rcBox in pixels.
>     'Left, Top are always 0, 0.
>     Debug.Print "ScaleWidth = " & rcBox.Right _
>         & "; ScaleHeight = " & rcBox.Bottom

> End Sub

> Rocky



> > Thanks, but I am using a MDI form which does not have ScaleWidth and
> > ScaleHeight.  I tried everything using the GetSystemMetrics function and I
> can
> > not
> > get the thickness of the border.  All I get is 4.  If I remove the
> titlebar from
> > the form I
> > can visually see the thickness of the border get smaller.  I try getting
> the
> > value and I
> > get 4.  Bring back the titlebar and the thickness gets bigger.  I try
> getting
> > the value
> > and I get 4.  I need the thickness.  I hope someone can shed some light.

> > Thanks.

> > Guy


> > > If you adjust your controls using ScaleWidth and ScaleHeight, the size
> of
> > > the borders won't matter. ScaleWidth/ScaleHeight are based on the client
> > > area of the form (the inside minus the borders, titlebar, etc.). If you
> want
> > > to find out when the border changes, just check for a change in
> > > ScaleWidth/ScaleHeight in the Paint event. Whenever a system property
> > > changes that would affect the size, style, color, etc of your form,
> Windows
> > > will send a WM_PAINT event to update the form.

> > > Example:
> > > Private Sub Form_Paint()

> > > Static fScaleWidth  As Single
> > > Static fScaleHeight As Single

> > >     If Me.ScaleWidth <> fScaleWidth Or _
> > >       Me.ScaleHeight <> fScaleHeight Then
> > >         fScaleWidth = Me.ScaleWidth
> > >         fScaleHeight = Me.ScaleHeight

> > >         'Note: Your resize function should be based
> > >         'on the ScaleWidth/ScaleHeight of the Form,
> > >         'instead of the Width/Height.
> > >         Call ResizeControls
> > >     End If

> > > End Sub

> > > Note: If your Form.AutoRedraw = True then you will need to find another
> way
> > > (subclassing or maybe a timer(yuk) control), since the Paint event will
> not
> > > fire while AutoRedraw is on.

> > > If you still need the border width/height, the following code will
> return
> > > them in twips:

> > >     BorderWidth = Me.Width - _
> > >       Me.ScaleX(Me.ScaleWidth, Me.ScaleMode, vbTwips)
> > >     BorderHeight = Me.Height - _
> > >       Me.ScaleY(Me.ScaleHeight, Me.ScaleMode, vbTwips)

> > > The Titlebar height can be calculated as follows:
> > >     TitlebarHeight = BorderHeight - BorderWidth

> > > Note: There are API functions to return these figures, but this is just
> as
> > > easy and you won't need any API declares.

> > > Hope this helps,

> > > Rocky



> > > > Hi,

> > > > I need to find out the size of the borders on a form.  If someone
> > > > changes their display settings from small fonts to big fonts the
> > > > thickness changes in the borders around the form and I have to detect
> > > > this in my app to make some adjustments of some controls.  While we
> are
> > > > here, is there also a way to get the height and width of the title
> bar?

> > > > Thanks for your time,

> > > > Guy

 
 
 

1. Q: How to restore (repaint) the caption bar/title bar of a form

I am temporarily painting my own stuff in the title bar of my
form but after that I would like to repaint the title area with
the original icon, the system buttons etc. I have tried with
invalidateRect, WM_NCPAINT and the Refresh in Delphi but I can
not figure out how to do it.

Thanks in advance,
Fredrik

2. Drawing Lines w/Arrowheads

3. Gradient Form Title Bar

4. flash 3

5. Making gradient in the form title bar

6. Deteriorating film filter??????

7. How to move a form with no title bar or caption VB 4.0 32 bit

8. Plugin programming!!!

9. Gradient on form Title bar

10. Changing the Color of a Form's Title Bar

11. How To Change Color of Form's Title Bar

12. How to drag a form without title bar

13. How can I draw form title bar???