Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find 1 of 3 windows
#1
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.)
#2
Function WindowFromScreen
Code:
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.

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

int hm
if flags&1
,hm=screenIndex
else if screenIndex=0
,hm=MonitorFromWindow(0 1)
else
,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
Code:
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.create(1)
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
Code:
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
#3
A very helpful and complete answer - thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)