[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:
Private Sub Form_Load()
Dim vDesiredHeight As Single
vDesiredHeight = 5000
Height = vDesiredHeight
Height = Height - 405 + (Height - ScaleHeight)
End Sub
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:
Option Explicit
Private Const CCHILDREN_TITLEBAR = 5
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type TITLEBARINFO
cbSize As Long
rcTitleBar As RECT
rgstate(CCHILDREN_TITLEBAR) As Long
End Type
Private Declare Function GetTitleBarInfo Lib "user32.dll" (ByVal hwnd As Long, ByRef pti As TITLEBARINFO) As Long
Private Sub Command1_Click()
Dim nfoTitle As TITLEBARINFO
nfoTitle.cbSize = Len(nfoTitle)
GetTitleBarInfo Me.hwnd, nfoTitle
MsgBox (nfoTitle.rcTitleBar.Bottom - nfoTitle.rcTitleBar.Top) * Screen.TwipsPerPixelY
End Sub
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:
Height = Height - 405 + (Height - ScaleY(ScaleHeight, ScaleMode, vbTwips))
And of course implement the Dog's suggestion. :thumb:
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.