Drawing Area Desktop object
Quote from kabilesh cobra on April 14, 2022, 1:37 pmI hope that you enjoyed your forklift training. The only time that I drove a forklift (without training but on order of foreman in a vacation job when I was a student and I hadn't even taken any car driving lessons let alone passed a driving test!) I drove it into a masonry column. Luckily, no damage to masonry column, forklift and (more importantly) to me, due to low speed!
Your Screenshot app needs a lot more code e.g. to process the SelectWindow class in its Form_Open into an array of Window Ids in Descending priority order, to check each Desktop Window against the array of Window Ids & the mouse click to be in it in the Mouse_Up event. I've almost got SelectWindow app working with that code included.
Public Sub Form_Open()Dim i As Integer
Dim hDesktopWindow As DesktopWindow
Dim sTest As String
Dim sWinIds As String
Inc Application.Busy
Shell "xprop -root | grep '_NET_CLIENT_LIST_STACKING(WINDOW)'" To sTest
' Put each X11 Window Id
' after stripping off comma & space separation characters
' from a string, returned by above xprop command, containing a list (in ascending priority order)
' into the aWinId array
Print sTest
sWinIds = Mid$(sTest, 48)
Print sWinIds
aWinId = Split(sWinIds, ",", "\n", True, False)
Print "Split"
For i = 0 To aWinId.Max
sTest = aWinId[i]
aWinId[i] = Mid(Trim(sTest), 3)
Print aWinId[i]
Next
aWinId.Reverse
Print "Reverse"
For i = 0 To aWinId.Max
Print aWinId[i]
Next
aWindow = []
iWindowLeft = 0
iWindowTop = 0
iWindowWidth = 0
iWindowHeight = 0
' Creates aWindow array of DesktopWindow objects
For Each i In Desktop.FindWindow(Null, Null, Null)
hDesktopWindow = New DesktopWindow(i)
With hDesktopWindow
If .Minimized Then Continue
If .VisibleName = "Desktop" And .Height = Screen.Height And .Width = Screen.Width Then Continue
aWindow.Add(hDesktopWindow)
If .FullScreen Then Continue
Print "DesktopWindow: ", "Name=" & .Name, "VisibleName=" & .VisibleName
Print "i=" & i, "Hex(i)=" & Hex(i)
Print "Id=" & .Id, "Hex(Id)=" & Hex(.Id)
Print "Left=" & .X, "Top=" & .Y, "Width=" & .Width, "Height=" & .Height
End With
FMain.PictureBoxArea.Clear
Next
Finally
Application.Busy = 0
Catch
Message.Warning(ERROR.Text & " at " & ERROR.Where)
EndPublic Sub DrawingAreaDesktop_MouseUp()
Dim i As Integer
Dim j As Integer
Dim sWindowName As String
Dim sWindowVisibleName As String
Dim sWindowid As String
Dim hWindow As DesktopWindow
Dim hWindowRect As Rect
Dim bWindowSelected As Boolean
Dim hPicture As Picture
Inc Application.Busy
bWindowSelected = False
Print "Mouse Position = " & Mouse.X & ", " & Mouse.Y
For i = 0 To aWinId.Max
For j = 0 To aWindow.Max
If Hex(aWindow[j].Id) = aWinId[i] And aWindow[j].Geometry.Contains(Mouse.X, Mouse.Y) Then
hWindow = aWindow[j]
hWindowRect = hWindow.Geometry
With hWindow
sWindowName = .Name
sWindowVisibleName = .VisibleName
sWindowId = .Id
End With
With hWindowRect
iWindowLeft = .Left
iWindowTop = .Top
iWindowWidth = .Width
iWindowHeight = .Height
End With
bWindowSelected = True
Break
End If
Next
If bWindowSelected Then
Print "Window Selected found in X11 Windows array"
Break
End If
Next
If bWindowSelected Then
Print "Window Selected"
Break
Else
' Last.Lock
Application.Busy = 0
Message.Title = "Try again:"
Message.Info("Did not click on window.")
' Last.Unlock
Return
End If
Print "You have selected this window:"
Print "Name=" & sWindowName, "VisibleName=" & sWindowVisibleName, "Id=" & sWindowId, "Hex(Id)=" & Hex(sWindowId)
Print "Left=" & iWindowLeft, "Top=" & iWindowTop, "Width=" & iWindowWidth, "Height=" & iWindowHeight
Last.Clear
Paint.Begin(Last)
Paint.LineWidth = 5
Paint.Rectangle(iWindowLeft, iWindowTop, iWindowWidth, iWindowHeight)
Paint.Stroke
Paint.End
Wait 3
Me.Hide 'Hide the Form
Wait 0.25 'Wait a little or you will get an opaque image
hPicture = Desktop.Screenshot(iWindowLeft, iWindowTop, iWindowWidth, iWindowHeight) 'ScreenShot of Selected Window
With FMain
.PictureBoxArea.Picture = hPicture 'Add Picture to PictureBoxArea on FMain form
.iRegionLeft = iWindowLeft
.iRegionTop = iWindowTop
.iRegionWidth = iWindowWidth
.iRegionHeight = iWindowHeight
End With
Me.Close
Finally
Application.Busy = 0
Catch
Message.Warning(ERROR.Text & " at " & ERROR.Where)
EndI have a question: I wanted to use the Lock method on Last (i.e. DrawingAreaDesktop object) to stop a click on the Ok button (generated by the Message.Title = "Try again:" & Message.Info("Did not click on window.") code as shown below, in order to stop the Mouse_Up event being executed again by the user clicking Ok in the Message Box. The code compiles Ok, but gives a runtime error about duplicate window (i.e. the Message Box) as the code or Mouse_Up event is executed due to clicking on the Ok button in the Message's window. How do I correct the Lock statement?
If bWindowSelected Then
Print "Window Selected"
Else
Last.Lock
Application.Busy = 0
Message.Title = "Try again:"
Message.Info("Did not click on window.")
Last.Unlock
Return
End If
I hope that you enjoyed your forklift training. The only time that I drove a forklift (without training but on order of foreman in a vacation job when I was a student and I hadn't even taken any car driving lessons let alone passed a driving test!) I drove it into a masonry column. Luckily, no damage to masonry column, forklift and (more importantly) to me, due to low speed!
Your Screenshot app needs a lot more code e.g. to process the SelectWindow class in its Form_Open into an array of Window Ids in Descending priority order, to check each Desktop Window against the array of Window Ids & the mouse click to be in it in the Mouse_Up event. I've almost got SelectWindow app working with that code included.
Public Sub Form_Open()
Dim i As Integer
Dim hDesktopWindow As DesktopWindow
Dim sTest As String
Dim sWinIds As String
Inc Application.Busy
Shell "xprop -root | grep '_NET_CLIENT_LIST_STACKING(WINDOW)'" To sTest
' Put each X11 Window Id
' after stripping off comma & space separation characters
' from a string, returned by above xprop command, containing a list (in ascending priority order)
' into the aWinId array
Print sTest
sWinIds = Mid$(sTest, 48)
Print sWinIds
aWinId = Split(sWinIds, ",", "\n", True, False)
Print "Split"
For i = 0 To aWinId.Max
sTest = aWinId
aWinId = Mid(Trim(sTest), 3)
Print aWinId
Next
aWinId.Reverse
Print "Reverse"
For i = 0 To aWinId.Max
Print aWinId
Next
aWindow = []
iWindowLeft = 0
iWindowTop = 0
iWindowWidth = 0
iWindowHeight = 0
' Creates aWindow array of DesktopWindow objects
For Each i In Desktop.FindWindow(Null, Null, Null)
hDesktopWindow = New DesktopWindow(i)
With hDesktopWindow
If .Minimized Then Continue
If .VisibleName = "Desktop" And .Height = Screen.Height And .Width = Screen.Width Then Continue
aWindow.Add(hDesktopWindow)
If .FullScreen Then Continue
Print "DesktopWindow: ", "Name=" & .Name, "VisibleName=" & .VisibleName
Print "i=" & i, "Hex(i)=" & Hex(i)
Print "Id=" & .Id, "Hex(Id)=" & Hex(.Id)
Print "Left=" & .X, "Top=" & .Y, "Width=" & .Width, "Height=" & .Height
End With
FMain.PictureBoxArea.Clear
Next
Finally
Application.Busy = 0
Catch
Message.Warning(ERROR.Text & " at " & ERROR.Where)
EndPublic Sub DrawingAreaDesktop_MouseUp()
Dim i As Integer
Dim j As Integer
Dim sWindowName As String
Dim sWindowVisibleName As String
Dim sWindowid As String
Dim hWindow As DesktopWindow
Dim hWindowRect As Rect
Dim bWindowSelected As Boolean
Dim hPicture As Picture
Inc Application.Busy
bWindowSelected = False
Print "Mouse Position = " & Mouse.X & ", " & Mouse.Y
For i = 0 To aWinId.Max
For j = 0 To aWindow.Max
If Hex(aWindow[j].Id) = aWinId And aWindow[j].Geometry.Contains(Mouse.X, Mouse.Y) Then
hWindow = aWindow[j]
hWindowRect = hWindow.Geometry
With hWindow
sWindowName = .Name
sWindowVisibleName = .VisibleName
sWindowId = .Id
End With
With hWindowRect
iWindowLeft = .Left
iWindowTop = .Top
iWindowWidth = .Width
iWindowHeight = .Height
End With
bWindowSelected = True
Break
End If
Next
If bWindowSelected Then
Print "Window Selected found in X11 Windows array"
Break
End If
Next
If bWindowSelected Then
Print "Window Selected"
Break
Else
' Last.Lock
Application.Busy = 0
Message.Title = "Try again:"
Message.Info("Did not click on window.")
' Last.Unlock
Return
End If
Print "You have selected this window:"
Print "Name=" & sWindowName, "VisibleName=" & sWindowVisibleName, "Id=" & sWindowId, "Hex(Id)=" & Hex(sWindowId)
Print "Left=" & iWindowLeft, "Top=" & iWindowTop, "Width=" & iWindowWidth, "Height=" & iWindowHeight
Last.Clear
Paint.Begin(Last)
Paint.LineWidth = 5
Paint.Rectangle(iWindowLeft, iWindowTop, iWindowWidth, iWindowHeight)
Paint.Stroke
Paint.End
Wait 3
Me.Hide 'Hide the Form
Wait 0.25 'Wait a little or you will get an opaque image
hPicture = Desktop.Screenshot(iWindowLeft, iWindowTop, iWindowWidth, iWindowHeight) 'ScreenShot of Selected Window
With FMain
.PictureBoxArea.Picture = hPicture 'Add Picture to PictureBoxArea on FMain form
.iRegionLeft = iWindowLeft
.iRegionTop = iWindowTop
.iRegionWidth = iWindowWidth
.iRegionHeight = iWindowHeight
End With
Me.Close
Finally
Application.Busy = 0
Catch
Message.Warning(ERROR.Text & " at " & ERROR.Where)
End
I have a question: I wanted to use the Lock method on Last (i.e. DrawingAreaDesktop object) to stop a click on the Ok button (generated by the Message.Title = "Try again:" & Message.Info("Did not click on window.") code as shown below, in order to stop the Mouse_Up event being executed again by the user clicking Ok in the Message Box. The code compiles Ok, but gives a runtime error about duplicate window (i.e. the Message Box) as the code or Mouse_Up event is executed due to clicking on the Ok button in the Message's window. How do I correct the Lock statement?
If bWindowSelected Then
Print "Window Selected"
Else
Last.Lock
Application.Busy = 0
Message.Title = "Try again:"
Message.Info("Did not click on window.")
Last.Unlock
Return
End If