Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find 1 of 3 windows
I have 3 open windows of Opera browser, each on own screen. How do I find/identify one of them individually? (Identifying by which screen would work, if I knew how.)
Function WindowFromScreen
Copy      Help
function# screenIndex ARRAY(int)&windows [flags] ;;flags: 1 screenIndex is screen handle

;From array of windows gets the first window that is on the specified screen.

;screenIndex - screen index. 0 primary, 1 first non-primary, and so on. The order is like in the array returned by function GetScreens.

;ARRAY(int) a; win("Opera" "" "" 0 "" a)
;int w=WindowFromScreen(1 a)
;outw w

int hm
if flags&1
else if screenIndex=0
,hm=MonitorFromWindow(0 1)
,int hPrimary=MonitorFromWindow(0 1)
,EnumDisplayMonitors 0 0 &sub.Proc 0
,if(hm=0) ret
int i
for i 0 windows.len
,int w=windows[i]
,if(MonitorFromWindow(w 2)=hm) ret w

#sub Proc v
function# hMonitor hdcMonitor RECT*lprcMonitor _
if(hMonitor!=hPrimary) screenIndex-1; if(screenIndex=0) hm=hMonitor; ret
ret 1

These functions are not used here, but can be useful when working with multiple screens.

Function GetScreens
Copy      Help
function ARRAY(int)&screens

;Gets array containing handles of all screens.
;Screen handles can be used with function GetScreenInfo to get screen rectangle etc.
;The first array element is the primary screen. Array elements are ordered differently than in Windows Settings.

screens[0]=MonitorFromWindow(0 1)
EnumDisplayMonitors 0 0 &sub.Proc &screens

#sub Proc
function# hMonitor hdcMonitor RECT*lprcMonitor ARRAY(int)&a
if(hMonitor!=a[0]) a[]=hMonitor
ret 1

Function GetScreenInfo
Copy      Help
function! hMonitor [RECT&bounds] [RECT&workArea] [int&isPrimary]

;Gets screen rectangle and other properties.

;hMonitor - screen handle. You can get it with functions GetScreens, MonitorFromWindow, MonitorFromPoint and MonitorFromRect.
;bounds - if used, receives screen rectangle. Pass 0 if don't need.
;workArea - if used, receives screen work area rectangle. Pass 0 if don't need.
;isPrimary - if used, receives 1 if it is the primary screen.

;Returns 1. Returns 0 if failed. Fails if screen handle is invalid.

MONITORINFO m.cbSize=sizeof(m)
if(!GetMonitorInfo(hMonitor &m)) ret
if(&bounds) bounds=m.rcMonitor
if(&workArea) bounds=m.rcWork
if(&isPrimary) isPrimary=m.dwFlags&1
ret 1
A very helpful and complete answer - thank you!

Forum Jump:

Users browsing this thread: 1 Guest(s)