Page 1 of 1
how to find a free place on big screen to open new Windows ?
Posted: Sun Mar 25, 2018 1:12 am
by Auge_Ohr
i can find out which Apps are running and get Pos/Size on Desktop.
now i want to open new Windows, any Size, and find a Position of a "free" (not Overlapped) Space on Desktop.
i do not want try/error like this ( too slow )
Code: Select all
FOR x := 1 TO aDesk[1]-aNewSize[1] STEP nXstep
FOR y := 1 TO aDesk[2]-aNewSize[2] STEP nYstep
aNewPos := {x,y}
FOR i := 1 TO LEN(aFenster)
aPos[1] := aFenster[i][xPos ]
aPos[2] := aFenster[i][yPos ]
aSize[1] := aFenster[i][xSize]
aSize[2] := aFenster[i][ySize]
IF HitWindow(aNewPos,aNewSize, aPos,aSize)
i wonder if i can use some sort of Delone Triangulation to find (best) free place on Desktop

Re: how to find a free place on big screen to open new Windo
Posted: Sun Mar 25, 2018 8:57 am
by rdonnay
i can find out which Apps are running and get Pos/Size on Desktop.
How are you getting the pos/size of those apps?
Re: how to find a free place on big screen to open new Windo
Posted: Sun Mar 25, 2018 10:46 am
by Auge_Ohr
rdonnay wrote:i can find out which Apps are running and get Pos/Size on Desktop.
How are you getting the pos/size of those apps?
using Tasklist and this
Code: Select all
FUNCTION GetaPosaSize(obj,aPos,aRefSize)
LOCAL nLeft := 0
LOCAL nTop := 0 // aPos == aRefSize == {nil,nil}
LOCAL nRight := 0 // passed by reference
LOCAL nBottom := 0
LOCAL cBuffer := SPACE(16)
// Get the absolute position and size of the Object (relative to DeskTop)
DllCall("User32.DLL",DLL_STDCALL,"GetWindowRect",obj:GetHWND(),@cBuffer)
nLeft := Bin2U(SUBSTR(cBuffer,1,4))
nTop := Bin2U(SUBSTR(cBuffer,5,4))
nRight := Bin2U(SUBSTR(cBuffer,9,4))
nBottom := Bin2U(SUBSTR(cBuffer,13,4))
aRefSize[ 1 ] := nRight - nLeft
aRefSize[ 2 ] := nBottom - nTop
aPos[ 1 ] := nLeft
aPos[ 2 ] := nTop
// For Xbase++ Coordinates, Bottom Left == 0,0 use.....
* aPos[2] := aRefSize[2] - nBottom
RETURN NIL
Re: how to find a free place on big screen to open new Windo
Posted: Sun Mar 25, 2018 11:06 am
by rdonnay
I get that part. I wrote a program that gets the PID and Window Title of all running tasks, but how do you get an Xbase++ object from that info?
Re: how to find a free place on big screen to open new Windo
Posted: Sun Mar 25, 2018 12:32 pm
by Auge_Ohr
you are right :
i´m not using oDlg Object from Tasklist, i use oDlg:GethWnd() Handle for "GetWindowRect"
Code: Select all
FUNCTION gettasklist( hWnd )
LOCAL aList := {}
LOCAL cWindowName
LOCAL nVisible
DO WHILE hWnd != 0
cWindowname := SPACE( 100 )
IF ( getwindowtexta( hWnd, @cWindowName, LEN( cWindowName ) ) <> 0 )
nVisible := IsWindowVisible( hWnd )
IF nVisible == 1
AADD( aList, STR( hWnd, 8 ) + cWindowname )
ENDIF
ENDIF
hWnd = GetWindow( hWnd, GW_HWNDNEXT )
ENDDO
RETURN aList
FUNCTION GetWindow( hWnd, uCmd )
LOCAL nDll := DllLoad( "USER32.DLL" )
LOCAL xRet := DllCall( nDll, DLL_STDCALL, "GetWindow", hWnd, uCmd )
DllUnLoad( nDll )
RETURN xRet
FUNCTION GetWindowTextA( hWnd, lPstring, nMax )
LOCAL nDll := DllLoad( "USER32.DLL" )
LOCAL xRet := DllCall( nDll, DLL_STDCALL, "GetWindowTextA", hWnd, @lPstring, nMax )
DllUnLoad( nDll )
RETURN xRet
FUNCTION IsWindowVisible( hWnd )
LOCAL nDll := DllLoad( "USER32.DLL" )
LOCAL xRet := DllCall( nDll, DLL_STDCALL, "IsWindowVisible", hWnd )
DllUnLoad( nDll )
RETURN xRet
Re: how to find a free place on big screen to open new Windo
Posted: Sun Mar 25, 2018 1:28 pm
by rdonnay
FUNCTION gettasklist( hWnd )
What is hWnd? It is obviously a window handle but from where?
Is it from AppDeskTop():getHwnd() ?
Re: how to find a free place on big screen to open new Windo
Posted: Sun Mar 25, 2018 2:58 pm
by Auge_Ohr
Code: Select all
LOCAL oDlg
LOCAL aTasklist
LOCAL aSize := { 0, 0 }
LOCAL aPos := { 0, 0 }
oDlg := XBPDIALOG() :new( APPDESKTOP(),, aPos, aSize,, .F. )
oDlg:clipSiblings := .T.
oDlg:drawingArea:ClipChildren := .T.
oDlg:create()
SETAPPFOCUS( oDlg )
aTasklist := GetTaskList( oDlg:gethWnd() )
FOR i := 1 TO LEN( aTasklist )