Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb form size under Vista Aero

Status
Not open for further replies.

HughLerwill

Programmer
Nov 22, 2004
1,818
GB
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?
 
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.
 
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.
 
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.
 
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:
[blue]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[/blue]
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top