Results 1 to 4 of 4

Thread: [RESOLVED] XP Theme / Win Classic Form Height

  1. #1

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Resolved [RESOLVED] XP Theme / Win Classic Form Height

    What does everyone think about this?

    The application I'm working on is run on a variety of different PCs, some XP, others not.

    On PCs set up with XP Theme display the forms' caption bars are thicker, making the available space on the form smaller. Most of our forms were designed before XP so many of them end up with some of the controls almost falling off the bottom.

    The following code appears to solve the problem, sizing the form appropriately for both XP and non-XP.

    Can anyone think of any problems with this? Are there other display modes I haven't thought about?

    The 405 value is the height of the title bar in Windows Classic. The height of the title bar in XP Themes is 510.

    VB Code:
    1. Private Sub Form_Load()
    2.   Dim vDesiredHeight As Single
    3.   vDesiredHeight = 5000
    4.   Height = vDesiredHeight
    5.   Height = Height - 405 + (Height - ScaleHeight)
    6. End Sub
    This world is not my home. I'm just passing through.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: XP Theme / Win Classic Form Height

    The only problem will be if the user is using a custom theme which has a different titlebar height then the two. There is an API that can get the info.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const CCHILDREN_TITLEBAR = 5
    4.  
    5. Private Type RECT
    6.     Left As Long
    7.     Top As Long
    8.     Right As Long
    9.     Bottom As Long
    10. End Type
    11.  
    12. Private Type TITLEBARINFO
    13.     cbSize As Long
    14.     rcTitleBar As RECT
    15.     rgstate(CCHILDREN_TITLEBAR) As Long
    16. End Type
    17.  
    18. Private Declare Function GetTitleBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByRef pti As TITLEBARINFO) As Long
    19.  
    20. Private Sub Command1_Click()
    21.     Dim nfoTitle As TITLEBARINFO
    22.     nfoTitle.cbSize = Len(nfoTitle)
    23.     GetTitleBarInfo Me.hwnd, nfoTitle
    24.     MsgBox (nfoTitle.rcTitleBar.Bottom - nfoTitle.rcTitleBar.Top) * Screen.TwipsPerPixelY
    25. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: XP Theme / Win Classic Form Height

    Another problem is that is the Scalemode of the form is not Twips then it won't work out. To fix this problem do this
    VB Code:
    1. Height = Height - 405 + (Height - ScaleY(ScaleHeight, ScaleMode, vbTwips))
    And of course implement the Dog's suggestion.

  4. #4

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: XP Theme / Win Classic Form Height

    Thanks to both of you.

    I think I can avoid using GetTitleBarInfo because I can garauntee that the forms will be designed under XP Themes (I will be using a titlebar height of 510 rather than 405).

    The resizing is only required if the user is running a different display mode/theme to the designer. Height-ScaleHeight returns the height of the titlebar so I'm going with moeur's suggestion (and changing the 405 to 510 as mentioned before).

    Reputation added to you both though.
    This world is not my home. I'm just passing through.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width