Results 1 to 8 of 8

Thread: How can I capture the desktop screen!

  1. #1

    Thread Starter
    Junior Member SkettaLEE's Avatar
    Join Date
    Oct 2001
    Location
    Shaw AFB, SC
    Posts
    30

    How can I capture the desktop screen!

    I would like to know the code to capture the current desktop screen and paste the picture in a picturebox in my form. Does anyone know how to do this? Help me if you can please!
    This is our world now, The world of the pop-trunk and the switch.
    The beauty of my Broad :-)
    We wage wars, murder, cheat, lie to our women and make them believe its for their own good. And we're the criminals.
    My crime is but of pimpology.
    I am a Pimp, and this is my manefesto!

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    VB Code:
    1. Private Declare Function GetDesktopWindow _
    2.  Lib "user32" () As Long
    3.  
    4. Private Declare Function GetDC _
    5.  Lib "user32" ( _
    6.  ByVal hwnd As Long) As Long
    7.  
    8. Private Declare Function ReleaseDC _
    9.  Lib "user32" ( _
    10.  ByVal hwnd As Long, _
    11.  ByVal hdc As Long) As Long
    12.  
    13. Private Declare Function BitBlt _
    14.  Lib "gdi32" ( _
    15.  ByVal hDestDC As Long, _
    16.  ByVal x As Long, _
    17.  ByVal y As Long, _
    18.  ByVal nWidth As Long, _
    19.  ByVal nHeight As Long, _
    20.  ByVal hSrcDC As Long, _
    21.  ByVal xSrc As Long, _
    22.  ByVal ySrc As Long, _
    23.  ByVal dwRop As Long) As Long
    24.  
    25. Private Sub CaptureDesktop()
    26.     Dim hWindow As Long
    27.     Dim hDContext As Long
    28.     [b]Picture1[/b].AutoRedraw = True
    29.     hWindow = GetDesktopWindow()
    30.     hDContext = GetDC(hWindow)
    31.     BitBlt [b]Picture1[/b].hDC, 0, 0,
    32.      Screen.Width \ Screen.TwipsPerPixelsX, _
    33.      Screen.Height \ Screen.TwipsPerPixelsY, _
    34.      hDContext, 0, 0, vbSrcCopy
    35.     [b]Picture1[/b].Refresh
    36.     [b]Picture1[/b].Picture = [b]Picture1[/b].Image
    37.     ReleaseDC hWindow, hDContext
    38. End Sub
    Best regards

  3. #3

    Thread Starter
    Junior Member SkettaLEE's Avatar
    Join Date
    Oct 2001
    Location
    Shaw AFB, SC
    Posts
    30

    Hmmm

    I just tried that code.............


    it said..........



    Member or Data Member not found

    and it highlighted


    .TwipsPerPixelsX



    can you help me?
    This is our world now, The world of the pop-trunk and the switch.
    The beauty of my Broad :-)
    We wage wars, murder, cheat, lie to our women and make them believe its for their own good. And we're the criminals.
    My crime is but of pimpology.
    I am a Pimp, and this is my manefesto!

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Sorry! I have typed it wrong. That happens sometimes when you type directly in the post instead of doing it in VB and then copy and paste the code

    Here's the correct procedure:
    VB Code:
    1. Private Sub CaptureDesktop()
    2.     Dim hWindow As Long
    3.     Dim hDContext As Long
    4.     Picture1.AutoRedraw = True
    5.     hWindow = GetDesktopWindow()
    6.     hDContext = GetDC(hWindow)
    7.     BitBlt Picture1.hdc, 0, 0, _
    8.      Screen.Width \ Screen.TwipsPerPixelX, _
    9.      Screen.Height \ Screen.TwipsPerPixelY, _
    10.      hDContext, 0, 0, vbSrcCopy
    11.     Picture1.Refresh
    12.     Picture1.Picture = Picture1.Image
    13.     ReleaseDC hWindow, hDContext
    14. End Sub
    Best regards

  5. #5

    Thread Starter
    Junior Member SkettaLEE's Avatar
    Join Date
    Oct 2001
    Location
    Shaw AFB, SC
    Posts
    30

    This is what i did!

    I got it to work by taking out the Twips part.. What did that part of the code do anyway? Thanx!
    This is our world now, The world of the pop-trunk and the switch.
    The beauty of my Broad :-)
    We wage wars, murder, cheat, lie to our women and make them believe its for their own good. And we're the criminals.
    My crime is but of pimpology.
    I am a Pimp, and this is my manefesto!

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    It re-calculates the Twips mesurement used by VB to pixels that you have to use in API calls. You should put them back otherwise this code will take much longer then necassary to call.

  7. #7
    Fanatic Member Kings's Avatar
    Join Date
    Aug 2001
    Posts
    673
    How would I make a screenshot of a specific window?
    I've got the classname (or handle) of the window
    K i n g s

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Use the FindWindow to get the hWnd of the window. Then use the above code from the GetDC call (and send the handle of the window).

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