ForunsBB

Tecnologia Programação e SEO para Webmasters
Data/Hora: 22 mai 2012, 14:05

Os Horários são TMG




Criar Novo Tópico Responder a este Tópico  [ 2 mensagens ] 
Autor Mensagem
 Assunto da Mensagem: [Visual Basic] Print screen
MensagemEnviado: 23 abr 2007, 22:53 
Offline
Nível 1
Nível 1

Registado: 15 jul 2005, 16:30
Mensagens: 167
Snippet para VB para fazer print screen no modo full window e active window

Código:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        GetWindowCapture().Save("c:\Teste.bmp")
    End Sub

    Public Function GetWindowCapture() As Image

        SendKeys.SendWait("%{PRTSC}")

        Dim objClipboard As IDataObject = Clipboard.GetDataObject()
        Return objClipboard.GetData(DataFormats.Bitmap)
    End Function

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        GetWindowCapture1().Save("c:\Teste.bmp")
    End Sub
    Public Function GetWindowCapture1() As Image

        SendKeys.SendWait("^{PRTSC}")

        Dim objClipboard As IDataObject = Clipboard.GetDataObject()
        Return objClipboard.GetData(DataFormats.Bitmap)
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class


Topo
 Perfil  
 
 Assunto da Mensagem:
MensagemEnviado:  




Topo
   
 
 Assunto da Mensagem: [Conversão de VB para Liberybasic] Print screen
MensagemEnviado: 23 abr 2007, 22:59 
Offline
Nível 1
Nível 1

Registado: 15 jul 2005, 16:30
Mensagens: 167
Conversão de VB para Libertybasic - Print screen
Já com o GUI so precisa de compilar com http://www.libertybasic.com. alternativa free http://www.justbasic.com mas com menos recursos.


Código:
'Escrito por whitehatg@gmail.com
             
    nomainwin
    WindowWidth = 350
    WindowHeight = 180
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    button #main.button1,"Full window",[button1Click], UL,  30,  57,  96,  25
    button #main.button2,"Active window",[button2Click], UL, 215,  57,  96,  25

    open "Print screen" for window as #main
    print #main, "font ms_sans_serif 10"
    print #main, "trapclose [quit.main]"


[main.inputLoop]
    wait

[button1Click]

bmpfile$=lower$(bmpfile$)
if right$(bmpfile$,4)<>".bmp" then bmpfile$=bmpfile$+".bmp"

hscreen=GetDC(0)
hmem=CreateCompatibleDC(hscreen)
hbitmap=CreateCompatibleBitmap(hscreen,DisplayWidth,DisplayHeight)
oldobject=SelectObject(hmem,hbitmap)

call BitBlt hmem,0,0,DisplayWidth,DisplayHeight,hscreen,0,0
call ReleaseDC 0,hscreen
call DeleteDC hmem

loadbmp "demo",hbitmap
bmpsave "demo","full_window.bmp"

call DeleteObject hbitmap
wait

[button2Click]

    vKeyAlt = _VK_MENU
    vKeyPrintScreen = _VK_SNAPSHOT
    vKeyControl = _VK_CONTROL
    vKeyV = 86

    Calldll #user32, "keybd_event", _
        vKeyAlt as Long, _
        null as Long, _
        0 as Long, _
        result as void

    Calldll #user32, "keybd_event", _
        vKeyPrintScreen as Long, _
        null as Long, _
        0 as Long, _
        result as void

    Calldll #user32, "keybd_event", _
        vKeyPrintScreen as Long, _
        null as long, _
        2 as Long, _
        result as void

    Calldll #user32, "keybd_event", _
        vKeyAlt as Long, _
        null as long, _
        2 as Long, _
        result as void

    Timer 1000, [active_window]
    Wait

[active_window]

     CallDLL #user32, "OpenClipboard", _
        hMain as Ulong, _
        result as Long

    CallDLL #user32, "GetClipboardData", _
        _CF_BITMAP as Long, _
        hImage as Ulong

    loadbmp "demo1", hImage

    Bmpsave "demo1", "Active_window.bmp"

    wait

[quit.main]
unloadbmp "demo"
unloadbmp "demo1"
    close #main
    end

Sub BitBlt hDCdest,x,y,w,h,hDCsrc,x2,y2
    CallDLL #gdi32, "BitBlt",hDCdest As uLong,_
    x As Long,y As Long,w As Long,h As Long,_
    hDCsrc As uLong,x2 As Long,y2 As Long,_
    _SRCCOPY As Ulong,RESULT As Boolean
    End Sub

Function SelectObject(hDC,hObject)
    CallDLL #gdi32,"SelectObject",hDC As uLong,_
    hObject As uLong,SelectObject As uLong
    'returns previously selected object
    End Function

Sub DeleteObject hObject
    CallDLL #gdi32,"DeleteObject",hObject As uLong,r As Boolean
    End Sub

Function CreateCompatibleBitmap(hDC,w,h )
    CallDLL #gdi32, "CreateCompatibleBitmap", hDC As uLong,_
    w As Long,h As Long, CreateCompatibleBitmap As uLong
    End Function

Function GetDC(hWnd)
    CallDLL #user32, "GetDC",hWnd As uLong,GetDC As uLong
    End Function

Sub ReleaseDC hWnd, hDC
    CallDLL#user32,"ReleaseDC",hWnd As uLong,_
    hDC As uLong,result As Long
    End Sub

Function CreateCompatibleDC(hDC)
    CallDLL #gdi32,"CreateCompatibleDC",_
    hDC As uLong, CreateCompatibleDC As uLong
    End Function

Sub DeleteDC hDC
    CallDLL #gdi32, "DeleteDC",hDC As uLong, r As Boolean
    End Sub




Com este pequeno exemplo em LB dp fiz algo assim mais confuso http://clientes.netvisao.pt/whitehat/prtsc/
é so dar largas á imaginação :wink:


Topo
 Perfil  
 
Mostrar mensagens anteriores:  Ordenar por  
Criar Novo Tópico Responder a este Tópico  [ 2 mensagens ] 

Os Horários são TMG


Tópicos Relacionados
 Tópicos   Autor   Respostas   Exibições   Última Mensagem 
Não há Mensagens novas não lidas neste Tópico. O que é o Visual Basic?

UnDeRGoD

1

430

24 abr 2012, 01:31

ajaxme A ver últimas Mensagens

Não há Mensagens novas não lidas neste Tópico. Threads em Visual Basic .NET

Alvarenga

4

201

10 mar 2011, 19:17

sBT498 A ver últimas Mensagens

Não há Mensagens novas não lidas neste Tópico. Visual Basic + Microsoft Access

xould

1

1516

23 set 2011, 15:42

ajaxme A ver últimas Mensagens

Não há Mensagens novas não lidas neste Tópico. Outras linguagens relacionadas com basic

whitehat

3

1654

22 abr 2007, 19:27

whitehat A ver últimas Mensagens

Não há Mensagens novas não lidas neste Tópico. [Liberty Basic] Player - powered by you

whitehat

1

1681

21 mai 2007, 21:21

whitehat A ver últimas Mensagens

 


Quem está ligado:

Utilizadores a ver este Fórum: Nenhum utilizador registado e 0 visitantes


Criar Tópicos: Proibído
Responder Tópicos: Proibído
Editar Mensagens: Proibído
Apagar Mensagens: Proibído
Enviar anexos: Proibído

Pesquisar por:
Ir para:  
Política de Privacidade | Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group