Brother Gabriel-Marie wrote  (on 15.08.2009 22:42):
> Mr. Bruce,  that "setworkarea" worked like a charm on my second 
> monitor.  Now I can leave my powerpro bar hanging around on the side and 
> still maximize to screen and reserve the space for my bar.  Thanks!
> 
> - Brother Gabriel-Marie


Hi there,

I'm not working frequently with multiple monitors, but thought you might 
like these few functions, especially "GetDesktopOfCaption":

// returns the number of desktops
@GetNumberOfDesktops
     Quit(win.GetSystemMetrics("SM_CMONITORS"))


// returns the desktop rectangle, i.e. "left top right bottom"
@GetDesktopRect
     Local _desknum = arg(1)
     if(_desknum >= ....@getnumberofdesktops)
         _desknum = 0
     Quit(win.GetDisplayRect(_desknum, 0))


// returns the desktop size, i.e. "width height"
@GetDesktopSize
     Local _desknum = arg(1)
     local _deskrect = ....@getdesktoprect(_desknum)

     local _left     = word(_deskrect, 1)
     local _top      = word(_deskrect, 2)
     local _right    = word(_deskrect, 3)
     local _bottom   = word(_deskrect, 4)
     local _xscreen = abs(_right - _left)
     local _yscreen = abs(_bottom - _top)

     Quit(_xscreen ++ " " ++ _yscreen)


// returns the desktop number of the given window caption,
// if any window with the matching caption can be found.
// it computes the overlapping area between the window and the desktops
// and returns the desktop with which the windows overlaps maximum
@GetDesktopOfCaption
     Local _caption = arg(1)
     Local _winhandle = win.handle(_caption)
     Local _desknum = -1
     ; win.debug("Found handle:", _winhandle)
     if(_winhandle)do
         local _deskcnt = ....@getnumberofdesktops

         local _overlapping_percentages = vec.create(_deskcnt)

         local _left = win.left(_winhandle)
         local _top = win.top(_winhandle)
         local _right = win.right(_winhandle)
         local _bottom = win.bottom(_winhandle)
         local _width = win.width(_winhandle)
         local _height = win.height(_winhandle)
         local _total_window_area = _width * _height
         ; win.debug("Window l,t,r,b,area:", _left, _top, _right, 
_bottom, _total_window_area)

         // iterate over the desktops and find overlapping areas
         for(local i=0; i<_deskcnt; i++)
             local _deskrect = ....@getdesktoprect(i)
             local _deskleft   = word(_deskrect, 1)
             local _desktop    = word(_deskrect, 2)
             local _deskright  = word(_deskrect, 3)
             local _deskbottom = word(_deskrect, 4)
             ; win.debug("Desk " ++ i ++ " rect,l,t,r,b:", _deskrect, 
_deskleft, _desktop, _deskright, _deskbottom)

             local _overlap_left, _overlap_top, _overlap_right, 
_overlap_bottom

             if(_left > _deskright || _right < _deskleft)do
                 _overlap_left = 0
                 _overlap_right = 0
             else
                 _overlap_left  = max(_left, _deskleft)
                 _overlap_right = min(_right, _deskright)
             endif

             if(_top > _deskbottom || _bottom < _desktop) do
                 _overlap_top = 0
                 _overlap_bottom = 0
             else
                 _overlap_top    = max(_top, _desktop)
                 _overlap_bottom = min(_bottom, _deskbottom)
             endif

             ; win.debug("Overlapping l,t,r,b: ", _overlap_left, 
_overlap_top, _overlap_right, _overlap_bottom)
             local _overlap_area = abs((_overlap_right - _overlap_left) 
* (_overlap_bottom - _overlap_top))
             local _overlap_percentage = _overlap_area * 100 / 
_total_window_area
             ; win.debug("overlap area, percentage:", _overlap_area, 
_overlap_percentage)

             _overlapping_percentages[i] = _overlap_percentage
         endfor

         // find the maximum overlapping percentage
         local _max_coverage = 0
         local _max_coverage_desknum = -1
         for(local j=0; j<_overlapping_percentages.length; j++)
             ; win.debug("Desktop:", j, "overlapping:", 
_overlapping_percentages[j]. "%")
             if(_overlapping_percentages[j] > _max_coverage)do
                 _max_coverage = _overlapping_percentages[j]
                 _desknum = j
             endif
         endfor

     ; win.debug("Found desktop:", _desknum)
     endif

     Quit(_desknum)


They should work with single-monitor setups as well.

HTH,
Cüneyt

Reply via email to