Results 1 to 5 of 5

Thread: getting the whole desktop

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    getting the whole desktop

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    4. ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    5.  
    6. Private Const KEYEVENTF_KEYUP = &H2
    7.  
    8. Private Function SaveFormPic() As Picture
    9.   Dim pic As StdPicture
    10.   Set pic = Clipboard.GetData(vbCFBitmap)
    11.   DoEvents
    12.   keybd_event vbKeySnapshot, 1, 0, 0
    13.   DoEvents
    14.   Set SaveFormPic = Clipboard.GetData(vbCFBitmap)
    15.   Clipboard.SetData pic, vbCFBitmap
    16. End Function
    17.  
    18. Private Sub Command1_Click()
    19.   SavePicture SaveFormPic, "C:\MyPic.jpg" 'picture location
    20. End Sub

    hey guys, the above code works fine but only grabs the active window, how can i make it grab the desktop, thanks!

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: getting the whole desktop

    you may try the link in my signature. it grabs the whole desktop, but i made it for a specific post, you may need to experiment and change the code according to your need.

    Harsh Gupta
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: getting the whole desktop

    thanks harsh but the bmp is far too big, nearly 3mb

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: getting the whole desktop

    Try this
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    4. ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    5.  
    6. Private Const VK_SNAPSHOT = &H2C
    7.  
    8. Private Function SaveScreen(ByVal theFile As String) As Boolean
    9. 'To get the Entire Screen
    10. Call keybd_event(vbKeySnapshot, 1, 0, 0)
    11.  
    12. 'To get the Active Window
    13. 'Call keybd_event(vbKeySnapshot, 0, 0, 0)
    14.  
    15. SavePicture Clipboard.GetData(vbCFBitmap), theFile
    16.  
    17. SaveScreen = True
    18.  
    19. End Function
    20.  
    21. Private Sub Command1_Click()
    22. Call SaveScreen("d:\shot1.bmp")
    23. End Sub

  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: getting the whole desktop

    Quote Originally Posted by Pouncer
    thanks harsh but the bmp is far too big, nearly 3mb
    yes, it because BMPs do have large file size. you may need some good JPG encoder class to convert it to encode it to small size, because VB does not create JPG files.

    you may search here to find one good JPG encoder thing, i dont remember exactly who posted it, but that was a good thing from Planet-source-code. so you may search PSC also.

    Harsh Gupta.
    Show Appreciation. Rate Posts.

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