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

Height of single-line menu bar

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
My menu can be displayed as a 1 or 2 line menu, depending on screen resolution.

Is it possible to test if it is displayed as 1 or 2 lines?

Thanks,
Sam
 
Sam,

I don't understand what you mean by "1 or 2 lines". What kind of lines are you referring to? Or do you mean 1 or 2 menu bars? But that's got nothing to do with the screen resolution.

Would SYSMETRIC(20) tell you what you need to know?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I just squeezed the _screen of the foxpro IDE, so the sysemnu takes one vs. two lines. The _screen.height changes, if the menu takes more space. Also, if the toolbar is undocked, of course. And if the user resizes the screen. So that's only an indicator. You should somehow be able to determine the windows total height from it's HWND anyway. Win API GetWindowRect.

If you compute the height of the Rect structure and subtract _screen.height you have the height of menu and docked toolbar(s).

I solved a problem with a too narrow (and therefore too high) toolbar by hiding it, if the desktop width was too small - but in my case the toolbar was just a shortcut of favorite menu items, which on netbooks was just not bearable. It took too much area and so it was decided to hide it on too small displays.

Bye, Olaf.

 
I just squeezed the _screen of the foxpro IDE, so the sysemnu takes one vs. two lines.

Ah, I see. Sam, you mean that, if the main Foxpro window is not wide enough to show the full width of the menu bar, then the menu bar will wrap round to a second line. Is that right?

If so, why exactly do you need to know that? If it's a step towards determining some other metric, maybe there's a simpler way of getting to your end goal.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I should have said "depending on screen width.." not "resolution". If the screen is not wide enough, the menu occupies 2 lines.

I need it to determine the TOP property of a form that shows in the TOP LEVEL FORM by computing sysmetric(9)+sysmetric(20)+the height of a tool bar.

sysmetric(9) gives the height of a single line only . It would be helpful if I could test for a 2 line menu and code it accordingly.

Sam
 
Thanks for the clarification, Sam.

I think you need OBJTOCLIENT() for this job. Pass an object reference to the form as the first parameter, and 1 as the second parameter. It will return the top of the form, relative to the top of the containing window, taking account all toolbars and menus.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, the top coordinate of a form in the top level form (_screen or your own top level form doesn't matter) directly under menu and toolbars is 0, always. And the available height for that form, when maximised, is _screen.height.

Bye, Olaf.
 
Mike,

OBJTOCLIENT gives the position relative to the form the object is on.

It doesn't help me as I would have to pass the MENU as an object, which I can't seem to do.

Sam
 
Olaf,

Does a menu have a window name ? For example such as "Shell_Traywnd" for the system tray.

It would be needed if I wanted to test the menu with the API GetWindowRect.

Sam
 
It doesn't help me as I would have to pass the MENU as an object, which I can't seem to do.

No. You pass the form as an object, not the menu.

If the form's object is named MyForm, and you want to find the top of MyForm, then you passs MyForm as the first parameter to OBJTOCLIENT().

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sam, I've been doing a bit of experimenting. I think you need something like this:

Code:
lnForm = OBJTOCLIENT(MyForm, 1)       && distance from top of form to top of physical screen
lnTop = viewport.Top                  && distance from top of form to top of _SCREEN client area
lnScreen = OBJTOCLIENT(_screen, 1)    && distance from top of VFP window to top of physical screen
lnMenus = lnForm - lnTop - lnScreen   && height of VFP's window's menus, top-docked toolbars, and top window border

I think the last of the above items is the one you are looking for.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
sdocker,

a menu is not a window like the systeray is, it's part of a window.
Also _screen is not the desktop, but the VFP IDE and also runtime top level form, if you don't do your own. All you need to pass in to GetWindowRect is the hwnd of the form, eg _screen.hwnd.

See news2news API declaration and sample usage:
Code:
DECLARE INTEGER GetWindowRect IN user32;
    INTEGER hWindow,;
    STRING @lpRect
cBuffer = REPLICATE(CHR(0), 16)
GetWindowRect( _screen.HWnd, @cBuffer )
 
? ctobin( SUBSTR(cBuffer, 1, 4),"SR" ), _screen.left
? ctobin( SUBSTR(cBuffer, 5, 4),"SR" ), _screen.top
? ctobin( SUBSTR(cBuffer, 9, 4),"SR")-ctobin( SUBSTR(cBuffer, 1, 4),"SR" ), _screen.width
? ctobin( SUBSTR(cBuffer, 13, 4),"SR" )-ctobin( SUBSTR(cBuffer, 5, 4),"SR" ), _screen.Height
Actually it doesn't give you any new info, I thought the Rect would be larger and include the title bar and menu, but it also only covers the viewport aka canvas of the winform.

There has to be some other API call including that.

Bye, Olaf.


 
It's even simpler, Mike.

Create a form you never show, and keep it at top = 0, like oForm = CreateObject("form").

Then simply OBJTOCLIENT(oForm, 1) is the distance of that form from the _screen top, so it's the height of menu + docked toolbars. I haven't tried what objtoclient returns, if the top level form is not the _screen.

On the other side, I think you overread me writing the top coordinate of a form always just needs to be 0 to appear right under menu and toolbars.

And the height available for forms inside the toplevel form is toplevelform.height, as that height already is reduced by title bar and menu and toolbar heights and status bar height. It's the inner height, eg a maximised vfp IDE _screen has _screen.width = 1280 and _Screen.height = 885 on a 1280x1024 desktop resolution. 885 is reduced by title bar, menu, toolbar, status bar and Windows task bar already. There are no calculations needed to determine that drawable area.

Bye, Olaf.



 
Nothing seems to work.

I have come to the conclusion that VFP assumes a 1 line menu bar, and with a 2 line menu bar the height coordinate of 0 is moved down a bit, but the various values returned are not affected.

As my form is designed at 640 x 480 and resized based on screen resolution, I reluctantly doubled the single line menu height if the end user resolution is 640 x 480.

Thanks for all the input.
Sam

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top