Finding height of all the menus and toolbars at the top of the Omnis frame

Scotte Meredith spomacguy at gmail.com
Thu Nov 6 17:19:12 UTC 2025


Thanks, Doug.


Scotte Meredith
spomacguy at gmail.com
509/998-0991




> On Nov 6, 2025, at 9:01 AM, Doug Easterbrook via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
> 
> ok everybody  Here we go.    The monitor list and sizes (for mac, since windows is an MDI Frame at the moment, but this code works on both)
> 
> What do I use this for:
> 1) make sure that if somebody reorients the monitor layout in MAC OS  apple system prefs, I know where to open the OMNIS window on the machine so people see it entirely
> 2) move a window to a monitor.   I have a menu that uses the monitor list generated in the code to have
> 	 Move to main monitor (1600x1600)
>         Move to Secondary monitor (800x 800)
> 3) when opening the window, I make sure I take care of omnis tool bar (and location) and open the window so that it is no bigger than the monitor that the window is on
> 4) doing a ’snap to monitor size’ so that if the window is too wide or tall for the monitor, I can force resizing to get it to fit the monitor.
> 
> 
> This need has been with me for a long time — and the code arrived in omnis 11.x to let me do it much better.
> 
> 
> I’ve given away the important code in this email.   I’ve got a lot more stuff in my app about window sizing and such …. maybe a good euromnis topic.
> 
> 
> 
> 
> 
> 
> 
> 
> Parameters:
> pCacheHeight - indicate if we want to force omnis to get the window menubar hegiht when we call it, or use the last value.  Was only for optimizing
> calling out to applescript
> 
> Local vars:
> Delimiter char
> height int 64 bit
> mainscreenheight in 64 bit default -1
> meuBarHeight int 64 default 24
> offsetX int 64
> OffsetY int 64
> OmnisY int64
> Screenlist - list
> ScreenString - char
> width in 64
> 
> 
> 
> # gets a list of screens on the users computer.    For windows, since its MDI interface, it will only have one.
> #
> 
> # get the menue bar height if this is a Mac Machine since the menu bar can be hidden/shown
> Do $cinst.$getMenuBarHeight(pCacheHeight) Returns menuBarHeight
> 
> # now find all the screen coordinates and adjust by the menu bar height to determine the omnis base coordinates
> Do screenList.$define(width,height,offsetX,offSetY,omnisY)
> 
> Calculate screenString as sys(240)
> Repeat
> Do method getNextMonitorToken (screenString,'[cxy_]',width.$ref,delimiter.$ref) Returns screenString
> Do method getNextMonitorToken (screenString,'[cxy_]',height.$ref,delimiter.$ref) Returns screenString
> Do method getNextMonitorToken (screenString,'[cxy_]',offsetX.$ref,delimiter.$ref) Returns screenString
> If delimiter='y'
> Calculate offsetX as -offsetX
> End If
> Do method getNextMonitorToken (screenString,'[cxy_]',offSetY.$ref,delimiter.$ref) Returns screenString
> If delimiter='y'
> Calculate offSetY as -offSetY
> End If
> 
> # Convert the values in sys(240) from MacOS coordinate space to Omnis coordinate space
> # purpose, omnis opens windows left (x), top (y)
> If mainScreenHeight<=0
> # at the start, the main screen height need to be adjusted by the height of the omnis menu bar
> # to ger the relative omnis creen (0,0) position
> Calculate mainScreenHeight as height-menuBarHeight
> Else
> # Get the top left of the screen rect, offset by main origin moving to top left and flip
> Calculate omnisY as offSetY+height-menuBarHeight
> Calculate omnisY as omnisY-mainScreenHeight
> Calculate omnisY as omnisY*-1
> End If
> 
> Do screenList.$add(width,height,offsetX,offSetY,omnisY)
> Until screenString=""
> 
> Quit method screenList
> 
> —————————————————————————————	
> the method —— getMonitorToken in the above
> Parameters
> pString character - is the output from sys(240) that we will parse
> pRegExp - character  — is the regular expression we are using to parse sys(240)
> pValue - item ref
> pDelimiter
> 
> Calculate returnString as pString
> Calculate length as len(returnString)
> Calculate startToken as rxpos(pRegExp,returnString,kTrue,kFalse,matchLen)
> Calculate pDelimiter as charat(returnString,startToken)
> Calculate returnString as right(returnString,length-startToken)
> Calculate endToken as rxpos(pRegExp,returnString,kTrue,kFalse,matchLen)
> 
> If endToken=0
> Calculate pValue as returnString
> Calculate returnString as ''
> Else
> Calculate pValue as mid(returnString,1,endToken-1)
> Calculate returnString as right(returnString,length-endToken)
> End If
> Quit method returnString
> 
> 
> 
> —————————————————————————————
> 
> for Scotte - the menubar height, which is $cinst.$getMenuBarHeight in the call above:
> Do $cinst.$getMenuBarHeight(pCacheHeight) Returns menuBarHeight
> 
> 
> If not(pCacheHeight)
> If not(I_DOS_MACHINE)
> Begin text block
> Line:tell application "System Events"
> Line:tell process "Omnis"
> Line:set menuBar to menu bar 1
> Line:set menuBarSize to size of menuBar
> Line:set height to item 2 of menuBarSize
> Line:return height
> Line:end tell
> Line:end tell
> End text block
> Get text block applescript
> Do code method Common.$doApplescript (applescript,result) Returns #F
> If flag true
> If len(result)
> Calculate cMenuBarHeight as result
> End If
> End If
> Else
> Breakpoint 
> # what do to for windows.
> End If
> End If
> Quit method cMenuBarHeight
> 
> 
> —————
> 
> how might you use this.    If omnis knows the monitors you have and their size.
> 
> $moveWindowToSelectedMonitor.  
> 
> 
> # moves a selected window from one monitor to another and makes sure it fits
> #
> # parameters
> # pMonitorList->the monitor we want to move the window to
> # pWindowRef->the referece to the window we want to move
> 
> If pMonitorList.$colcount=0
> Breakpoint where is the row containing the monitor dimensions we want to move things to?
> Quit method kFalse
> End If
> 
> If pWindowRef=''
> Breakpoint where is the reference to the window to be moved
> Quit method kFalse
> End If
> 
> If $cparmcount<4
> Breakpoint missing the references to integers pTopBorder and pLeftBorder probabably
> Quit method kFalse
> End If
> 
> If isclear(pTopBorder)|isclear(pLeftBorder)
> Calculate topBorder as 5
> Calculate leftBorder as 5
> Else
> Calculate topBorder as pTopBorder
> Calculate leftBorder as pLeftBorder
> End If
> 
> # set the top/left as 5 pixels in on the monitor (based on values in topBorder,LeftBorder)
> # unless cascading the windows in a repeated loop and we are given different starting position
> Calculate pWindowRef.$top as pMonitorList.omnisY+topBorder
> Calculate pWindowRef.$left as pMonitorList.offsetX+leftBorder
> 
> # make sure window width fits on monitor and account for top starting position
> If pWindowRef.$width+rightBorderMin+leftBorder>pMonitorList.width
> Calculate pWindowRef.$width as pMonitorList.width-rightBorderMin-leftBorder
> End If
> # and window height fits on main monitor
> If pWindowRef.$height+bottomBorderMin+topBorder>pMonitorList.height
> Calculate pWindowRef.$height as pMonitorList.height-bottomBorderMin-topBorder
> End If
> 
> 
> 
> how would you use the above to move a window from one monitor to another…   This, for example, cascades all open
> windows on a specific monitor
> 
> If pMonitorList.$colcount<=0
> Calculate list as $cinst.$getMonitorlist
> Calculate pMonitorList as list.1
> End If
> 
> Do $cinst.$buildOpenWindowList('Top',kFalse,kTrue) Returns windowList
> If windowList.$linecount=0
> Quit method kTrue
> End If
> 
> Do windowList.$first(kFalse,kTrue) Returns #F
> While flag true
> Set reference windowRef to windowList.iWindowRef
> 
> # if window is minimized, then $maximize it when cascading
> If windowRef.$minimized
> Calculate windowRef.$maximized as kTrue
> End If
> If $cinst.$moveWindowToSelectedMonitor.$cando
> Do $cinst.$moveWindowToSelectedMonitor(pMonitorList,windowRef,topBorder,LeftBorder)
> End If
> 
> Calculate topBorder as topBorder+22 ## space to see title
> Calculate LeftBorder as LeftBorder+15
> 
> Do windowList.$next(0,kFalse,kTrue) Returns #F
> End While
> Quit method kTrue
> 
> 
> 
> 
> Doug Easterbrook
> doug at artsman.com
> 
>> On Nov 4, 2025, at 4:17 PM, Scotte Meredith <spomacguy at gmail.com> wrote:
>> 
>> I know this has been asked before, but I can't find an answer. I'm trying to find the height of all the menus and toolbars at the top of the entire Omnis application frame so I know how much room I actually have for a client window. 
>> 
>> -- Menubar
>> -- One or more rows of toolbars installed at the top fo the window that may be normal or large icons
>> ---- My window is sitting just below this
>> 
>> ______
>> |
>> |  I need to know much room I have here so I can turn on scrollbars only if there is not enough room and set the height of the window.
>> |  sys(104), sys(105) give me the size of the whole screen area.
>> |____
>> -- Bottom of the screen.
>> 
>> I figured out a kludge, where I have another empty window I open, $maximize, get the $height and $close it. That tells me the maximum size of a window inside of the entire Omnis frame, then I can subtract that from sys(105) to get the total for the other "stuff". I can do that on startup to get the size and save it.
>> 
>> Anyone have a more elegant way?
>> 
>> 
>> Scotte Meredith
>> spomacguy at gmail.com
>> 509/998-0991
>> 
>> 
>> 
>> 
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 



More information about the omnisdev-en mailing list