Where is the top/bottom of the screen?

Graham Samuel graham.samuel at wanadoo.fr
Mon Dec 15 09:21:56 EST 2003


On Mon, 15 Dec 2003 15:33:23 +1100, Igor Couto <igor at pixelmedia.com.au> wrote:


>Does anyone have a quick and easy way to determine where the VISIBLE
>topLeft of the user's screen is? - I mean, the Macintosh menubar takes
>a couple of dozen pixels, I think, so if we set a stack's topLeft to
>0,0, we end up with its top 'chopped off' by the menubar.
>
>I know that other operating systems (ie, Linux) can have menu (and
>other types of) bars across the top - and bottom - of the screen,
>too...
>
>Is there a generic way to find out where the VISIBLE' top/bottom of the
>screen is? - so that we can create stacks that 'snap' to the top or
>bottom edge of the screen...

Hi Ivor

I don't think there is a universal quick and easy way: there is also the 
issue of whether you want to refer to the top left of the titlebar of your 
window, or the top left of the actual window contents. Although this may 
not after all be what you're looking for, FWIW I have the following info, 
which comes out of an app I've written that wants to use all the available 
space without bumping into title bars, toolbars, menubars etc. The workable 
rectangle (i.e. the part of the screen you can use to write pixels into) is 
generated in the variable gMyRect:

-- The WindowBoundingRect is set by default to avoid the toolbars and stuff 
on the screen
   -- but it seems we have to do our own calculations to make room for the 
window's title bar
   -- and side and bottom decorations. This table was created by experiment:
   --    OS        Platform  SystemVersion  Title Bar LeftSide RightSide Bottom
   --  Windows 95    Win32       4.0            24      4          4        4
   --  Windows 98    Win32       4.10           24      4          4        4
   --  Windows XP    Win32       NT 5.1         30      4          4        4
   --  Mac OS 9      MacOS       9.2.2          22      6          7        6
   --  Mac OS X      MacOS       10.2.6         22      1          1        1
   --
     put the windowBoundingRect into gMyRect-- left, top, right, bottom
     put the SystemVersion into SClSysVer
     if the platform is "Win32" then
       -- in principle the user can alter the height of the title bar
       -- thanks to Ken Ray and Jan Schenkel for explaining this technique
       put "HKEY_CURRENT_USER\Control 
Panel\desktop\WindowMetrics\CaptionHeight" into SClRegKey
       put queryRegistry(SClRegKey) into SClCaptionHeight

       put abs(SClCaptionHeight DIV 15) + 5 into SClTitleHeight
       add SClTitleHeight to item 2 of gMyRect
       add 4 to item 1 of gMyRect -- left edge
       subtract 4 from item 3 of gMyRect  -- right edge
       subtract 4 from item 4 of gMyRect  -- bottom
     else
       if the platform is "MacOS" then
         set the itemDelimiter to "." -- versions are of the form "x.y.z"
         if item 1 of sclSysVer >= 10 then -- it's OSX
           set the itemDelimiter to ","
           add 22 to item 2 of gMyRect  -- top
           add 1 to item 1 of gMyRect  -- left
           subtract 1 from item 3 of gMyRect  -- right
           subtract 1 from item 4 of gMyRect  -- bottom
         else
           set the itemDelimiter to "," -- it's an earlier MacOS
           add 22 to item 2 of gMyRect -- top
           add 6 to item 1 of gMyRect  -- left
           subtract 7 from item 3 of gMyRect -- right
           subtract 6 from item 4 of gMyRect -- bottom
         end if
         -- we assume that Unix doesn't get a look in
       end if
     end if
     set the windowBoundingRect to gMyRect
     set the rectangle of this stack to gMyRect

HTH

Graham


---------------------------------------------------
Graham Samuel / The Living Fossil Co. / UK & France  




More information about the use-livecode mailing list