×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

vb form size under Vista Aero

vb form size under Vista Aero

vb form size under Vista Aero

(OP)
Dear all,
VB Forms displayed with Aero enabled are a little larger (all round) than their properties suggest. I guess there is an API call (or a pair of them) which returns the width/ height of the fat borders; anyone know what it is?

RE: vb form size under Vista Aero

Since knowing each measurement isn't always required you can often get by with the difference between Width & ScaleWidth (outer and inner) and between Height & ScaleHeight.  If that works for you just use something like:

CODE

Option Explicit

Private Function HPadding(ByVal Form As Form)
    Dim SaveMode As Integer
    
    With Form
        SaveMode = .ScaleMode
        .ScaleMode = vbTwips
        HPadding = .Width - .ScaleWidth
        .ScaleMode = SaveMode
    End With
End Function

Private Function VPadding(ByVal Form As Form)
    Dim SaveMode As Integer
    
    With Form
        SaveMode = .ScaleMode
        .ScaleMode = vbTwips
        VPadding = .Height - .ScaleHeight
        .ScaleMode = SaveMode
    End With
End Function

Private Sub Command1_Click()
    Print HPadding(Me), VPadding(Me)
End Sub
Different styles of windows (Forms) have different border padding and title bar heights.

RE: vb form size under Vista Aero

(OP)
dilettante, thanks but Width and Height do appear to be lying for Forms with fixed borders;

'code in Form1
Private Sub Command1_Click()
    Form2.Show
    Form2.Left = Form1.Left + Form1.Width
    Form2.Top = Top
End Sub

Private Sub Form_Load()
    Top = 0
    Left = 0
End Sub

'under Aero Form2's left border overlaps Form1's right border unless both forms have BorderStyle sizeable
'additionally if Form1 has fixed BorderStyle its Top and Left edges are clipped off the primary monitor.

RE: vb form size under Vista Aero

I see what you're saying.  The internal metrics reflect pre-Aero values but the forms actually display with Aero border widths.  My guess is that the visible desktop is rendered after the fact from a hidden "legacy" desktop.

Frequently asked questions about the Aero Basic window frame

RE: vb form size under Vista Aero

(OP)
dilettante - Thanks for the link. Even after retrieving iPaddedBorderWidth via SystemParametersInfo I think it may be quite messy to get a Fixed sized Form to behave like a Sizable one.

I wonder if it may be better to just use a Sizable Form in the first place and then prevent it being resized with a kludge like;

Private Sub Form_Resize()
    Static init As Boolean, refheight As Long, refwidth As Long
    If Not init Then
        'capture design time Height and Width when Form is first Shown
        refheight = Height
        refwidth = Width
        init = True
        Exit Sub
    End If
    'and prevent change
    If Width <> refwidth Then Width = refwidth: Exit Sub
    If Height <> refheight Then Height = refheight
End Sub

The downside is that the Form still appears sizable because the sizing arrows appear when the Mouse moves over its edges and sizing options are present in its control menu.

RE: vb form size under Vista Aero

Does the DWMWA_EXTENDED_FRAME_BOUNDS attribute of the DwmGetWindowAttribute API call help?
Something like (and I've just put this together without VB, as I don't have it on the Vista machine I;'m on at the moment):

CODE

Option Explicit

Private Enum DWMWINDOWATTRIBUTE
    DWMWA_NCRENDERING_ENABLED = 1
    DWMWA_NCRENDERING_POLICY
    DWMWA_TRANSITIONS_FORCEDISABLED
    DWMWA_ALLOW_NCPAINT
    DWMWA_CAPTION_BUTTON_BOUNDS
    DWMWA_NONCLIENT_RTL_LAYOUT
    DWMWA_FORCE_ICONIC_REPRESENTATION
    DWMWA_FLIP3D_POLICY
    DWMWA_EXTENDED_FRAME_BOUNDS
    DWMWA_LAST
End Enum

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

Private Declare Function DwmGetWindowAttribute Lib "dwmapi.dll" (ByVal hwnd As Long, ByVal dwAttribute As Long, ByRef pvAttribute As Any, ByVal cbAttribute As Long) As Long

Public Sub example()
    Dim wombat As RECT
    Debug.Print DwmGetWindowAttribute(Application.hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, wombat, LenB(wombat))
' wombat now contains our measurements
End Sub
 

RE: vb form size under Vista Aero

(OP)
strongm - thanks - a tiny change from Application.hwnd to me.hwnd and your code worked. This certainly makes determination of the actually rect occupied by the fixed window easier. Having got that info though we are left to manually shift the window and any that we place adjacent to its edges (the messy bit).
Apart from the drawbacks noted in my previous it still seems easier to use a Sizable Form behave like a Fixed sized one and let the OS handle things.
I know prevention of resize can be handled more elegantly by sub-classing the Form. Is it possible to prevent display of the resize arrows when the mouse moves over the Form edges? Can the resize options in its Control menu be removed.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close