lunes, 5 de diciembre de 2016

Captura la Ventana activa

Código original extraído de IDE Gambas 3.9


' gambas class file

Public Sub Form_Open()

Me.W = btnTakeScreenshot.Font.TextWidth(btnTakeScreenshot.Text) + Desktop.Scale * 14
Me.Move(Desktop.X + Desktop.W - Me.W, Desktop.Y)

End


Public Sub btnTakeScreenshot_Click()

Dim hWindow As DesktopWindow
Dim hPict As Picture
Dim I As Integer
Dim sDir As String
Dim sPath As String

Me.Hide
Wait 0.1

hWindow = New DesktopWindow(Desktop.ActiveWindow)
hPict = hWindow.GetScreenshot()

sDir = Project.Dir &/ ".hidden/screenshots"
For I = 1 To 999
sPath = sDir &/ Format(Now, "yyyy-mm-dd")
If I > 1 Then sPath &= "-" & CStr(I)
sPath &= ".png"
If Not Exist(sPath) Then
If Not IsDir(sDir) Then Project.InsertDirectory(sDir)
hPict.Save(sPath)
Project.InsertFile(File.Name(sPath), File.Dir(sPath))
Break
Endif
Next

Me.Show

End

Public Sub btnClose_Click()

Me.Close

End


Aquí mi adaptación al ejemplo que queria hacer.

' gambas class file

'Código extraído de gambas (FScreenshot)
'Modificado por postapase para hacer un ejemplo
'Este ejemplo captura una foto de la ventana activa

Private sDir As String

Public Sub Form_Open()
Me.W = btnTakeScreenshot.Font.TextWidth(btnTakeScreenshot.Text) + Desktop.Scale * 14
Me.Move(Desktop.X + Desktop.W - Me.W, Desktop.Y)

sDir = User.Home &/ "MisCapturas"

If Not Exist(sDir) Then
Mkdir sDir
Wait 0.1
Endif
End

Public Sub btnTakeScreenshot_Click()
Dim hWindow As DesktopWindow
Dim hPict As Picture
Dim I As Integer
Dim sPath As String

Me.Hide
Wait 0.1

hWindow = New DesktopWindow(Desktop.ActiveWindow)
hPict = hWindow.GetScreenshot()

For I = 1 To 999
sPath = sDir &/ Format(Now, "yyyy-mm-dd")
If I > 1 Then sPath &= "-" & CStr(I)
sPath &= ".png"
If Not Exist(sPath) Then
hPict.Save(sPath)
Break
Endif
Next

Me.Show

End

Public Sub btnClose_Click()
Me.Close
End

Public Sub ToolButtonDir_Click()
If Not Exist(sDir) Then Return
Desktop.Open(sDir)
End

El código fuente esta en la Granja de Gambas, Saludos.

No hay comentarios.:

Publicar un comentario