Mostrando las entradas con la etiqueta Exist. Mostrar todas las entradas
Mostrando las entradas con la etiqueta Exist. Mostrar todas las entradas

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.

domingo, 6 de noviembre de 2016

Ejemplo Temp()


' gambas class file

'by postapase
'http://novatocodegambas.blogspot.com.uy/

Public ArchivoTemporal As File
Public RutaArchivo As String = User.home
Public RutaArchivoTemporal As String
Public Contador As Integer


Public Sub Form_Open()

RutaArchivoTemporal = Temp()
LabRutaTemporal.Text = RutaArchivoTemporal
TextArea1.Clear()
btnGuardarArchivo.Enabled = False

End

Public Sub btnAgregarTexto_Click()

ArchivoTemporal = Open RutaArchivoTemporal For Write Append

Write #ArchivoTemporal, TextBox1.Text & gb.NewLine

Close #ArchivoTemporal

LeerDatosArchivoTemporal()

btnGuardarArchivo.Enabled = True

TextBox1.Clear()
TextBox1.SetFocus()

End

Public Sub LeerDatosArchivoTemporal()
Dim LineaX As String

TextArea1.Clear()

ArchivoTemporal = Open RutaArchivoTemporal For Read

While Not Eof(ArchivoTemporal)
Line Input #ArchivoTemporal, LineaX
TextArea1.Text = LineaX & gb.NewLine & TextArea1.Text
Wend

Close ArchivoTemporal

End

Public Sub Button1_Click()

Form_Open()

End

Public Sub btnGuardarArchivo_Click()

Inc Contador

If Exist(RutaArchivo &/ "EjemploTemp-" & Contador) Then btnGuardarArchivo_Click()

Copy RutaArchivoTemporal To RutaArchivo &/ "EjemploTemp-" & Contador

End



Código fuente: Ejemplo-Temp-0.0.1.tar.gz