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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting height of titlebar and menubar 2

Status
Not open for further replies.

Devin

Programmer
Dec 17, 2001
42
US
I just know there must be an easy answer to this. It is totally critical for positioning graphical objects. I looked in VB help and searched this forum but found nothing...

I know I can use sysinfo.workareaheight to get the height of the desktop less the taskbar height. I am unable to figure out, though, how to get the titlebar and menubar heights. It seems like it should be accessible via the sysinfo control.

Ideally, I would like to directly detect the working area of a given form that I load maximized -- that is, the height from the bottom of the pull-down menu-bar to the top of the task-bar (if there is one).
 
You can call the GetSystemMetrics function to query these (and many other) system parameters.
___

Private Declare Function GetSystemMetrics& Lib "user32" (ByVal nIndex&)
Const SM_CYCAPTION = 4
Const SM_CYMENU = 15
Private Sub Form_Load()
MsgBox GetSystemMetrics(SM_CYCAPTION), , "Titlebar height"
MsgBox GetSystemMetrics(SM_CYMENU), , "Menubar height"
End Sub
 
thx, Hypetia. That is just what I needed. There's a star for you.
 
> It seems like it should be accessible via the sysinfo control

What do you get when you subtract this from Screen.Height?
 
If you start with sysinfo.workareaheight (which may or may not be equal to screen.height, depending on the taskbar properties) and subtract the above titlebar and menubar heights, then you get the total "usable height" of the form. (My form is maximized, so I don't care about borders.) I find it very strange that the form object does not have this value as a property. How can one appropriately position graphical elements without it?!

I was originally just subtracting a constant value from form.height, but the problem I was having is that the titlebar height varies depending on your display prefs. Those worthless rounded titlebars in XP-style display are considerably bigger than the default Classic-style titlebars.

Aside: I'll never understand why someone would choose pretty over fast and lean, when it comes to their operating system. I had better not get started on this rant. I'm sure most of the people that read this board, clicked the "optimize for best performance" button the day they installed XP. I'm preaching to the choir.
 
>form object does not have this value as a property

Form1.ScaleHeight

form actual height or form workable area have nothing to do with sysinfo.workareaheight.

Screen.Height = 15360
sysinfo1.WorkAreaHeight = 14940

Form1.Height = 11850
Form1.ScaleHeight = 11445
 
Now I feel stupid. I knew it had to be easier than that. My work-around is effective but totally unnecessary! I go through all of that computation to derive a property that is already there. Thanks, CCLINT.
 

We've all been down that road before, and even still run off into the ditch often enough.
This is why exchange, and reading here in Tek-Tips is so worthwhile...
 
Here's the problem with form.scaleheight...

Scaleheight is generally the working height of the form, but when the form is maximized and the border does not exist, scaleheight is the true working height less twice the border height. So, I end up with a stip of unused vertical space at the bottom of the form. With a maximized form, it seems you must actually use the following code:

Private Declare Function GetSystemMetrics& Lib "user32" (ByVal nIndex&)
Const SM_CYCAPTION = 4
Const SM_CYMENU = 15

titleBarHeight = GetSystemMetrics(SM_CYCAPTION)
menuBarHeight = GetSystemMetrics(SM_CYMENU)
usableHeight = Screen.Height - ((titleBarHeight + menuBarHeight) * Screen.TwipsPerPixelY)


Can anyone recommend a general solution to finding the true working height that is effective for normal and maximized windows?
 
Odd. ScaleHeight works fine in the scenario you outline on the NT4 box I'm working on at the moment (note that ScaleHeight is really just a wrapper for the GetClientRect API call)
 
hmmm... The form is maximized by default, so it's not a resizing issue. I don't understand, either.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top