Results 1 to 6 of 6

Thread: Grabing The Desktop And Putting It In A Picture Box

  1. #1

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172

    Grabing The Desktop And Putting It In A Picture Box

    hello people i want to grab the screen and put it in a picture box how can i do this? if found some things but they dont work

    i want it to be captured on a button click name of the button GRAB and picturebox = picturegrab

    this is on of the files i found



    code:--------------------------------------------------------------------------------
    Declare Function BitBlt Lib "gdi32" _
    (ByVal hDestDC As Integer, ByVal x As Integer, _
    ByVal y As Integer, ByVal nWidth As Integer, _
    ByVal nHeight As Integer, ByVal _
    hSrcDC As Integer, ByVal xSrc As Integer, _
    ByVal ySrc As Integer, ByVal dwRop As _
    Long) As Integer

    Declare Function GetDesktopWindow Lib "user32" () As Long

    Declare Function GetDC Lib "user32" _
    (ByVal hwnd As Long) As Long

    Sub Grabscreen(Dest As PictureBox)
    Dim DeskhWnd As Long, DeskDC As Long

    'Get the hWnd of the desktop
    DeskhWnd = GetDesktopWindow()

    'BitBlt needs the DC to copy the image. So, we
    'need the GetDC API.
    DeskDC = GetDC(DeskhWnd)

    Dest.AutoRedraw = True
    BitBlt Dest.hDC, 0, 0, _
    Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, DeskDC, _
    0, 0, vbSrcCopy
    Dest.Refresh
    End Sub
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    2.  
    3. Private Const VK_SNAPSHOT = &H2C
    4.  
    5. Private Function SaveScreen(ByVal theFile As String) As Boolean
    6. On Error Resume Next
    7.  
    8. 'To get the Entire Screen
    9. Call keybd_event(vbKeySnapshot, 1, 0, 0)
    10.  
    11. 'To get the Active Window
    12. 'Call keybd_event(vbKeySnapshot, 0, 0, 0)
    13.  
    14. SavePicture Clipboard.GetData(vbCFBitmap), theFile
    15.  
    16. SaveScreen = True
    17.  
    18. End Function
    19.  
    20. Private Sub Command1_Click()
    21. Call SaveScreen("C:\Program Files\shot1.bmp")
    22. Picture1.Picture = LoadPicture("C:\Program Files\shot1.bmp")
    23. End Sub

  3. #3

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    OK but i dont want to save it to file but bring it to a picture box :S
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  4. #4

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    oh doh... but is there a way to make it direct instead of letting it save first and then load? cant i set it to the box imediatly?
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  5. #5

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    OK fixed this myself.. but eer.. it only grabs the current form.. not the entire desktop
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

  6. #6

    Thread Starter
    Frenzied Member Ultimasnake's Avatar
    Join Date
    Feb 2002
    Location
    Amsterdam, holland
    Posts
    1,172
    this is the code

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Private Const VK_SNAPSHOT = &H2C

    Private Function SaveScreen() As Boolean
    On Error Resume Next

    'To get the Entire Screen
    Call keybd_event(vbKeySnapshot, 1, 0, 0)

    'To get the Active Window
    'Call keybd_event(vbKeySnapshot, 0, 0, 0)

    picture1.Picture = Clipboard.GetData(vbCFBitmap)

    SaveScreen = True

    End Function

    Private Sub Command1_Click()
    Call SaveScreen
    End Sub
    For my PC and MS Smartphone 2003 software visit
    http://www.ultimasoftware.nl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width