how to find a free place on big screen to open new Windows ?

This forum is for general support of Xbase++
Post Reply
Message
Author
User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

how to find a free place on big screen to open new Windows ?

#1 Post 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 :?:
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: how to find a free place on big screen to open new Windo

#2 Post 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?
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: how to find a free place on big screen to open new Windo

#3 Post 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
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: how to find a free place on big screen to open new Windo

#4 Post 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?
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: how to find a free place on big screen to open new Windo

#5 Post 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
greetings by OHR
Jimmy

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: how to find a free place on big screen to open new Windo

#6 Post by rdonnay »

FUNCTION gettasklist( hWnd )
What is hWnd? It is obviously a window handle but from where?

Is it from AppDeskTop():getHwnd() ?
The eXpress train is coming - and it has more cars.

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: how to find a free place on big screen to open new Windo

#7 Post 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 )
greetings by OHR
Jimmy

Post Reply