Results 1 to 4 of 4

Thread: Copying desktop to picture box

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Question

    I'm still a bit of a dunce when it comes to using BitBlt - it's the next thing on my list of things to learn about. However, I was confused when I tried to use a snippet of code from VBWorld. It's found at http://www.vbsquare.com/tips/tip276.html, but I've copied it out below to save you the trouble of going there!

    Code:
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    
    Private Const SRCCOPY = &HCC0020
    Private Const SRCAND = &H8800C6
    Private Const SRCINVERT = &H660046
    
    
    
    Private Sub Form_Load()
    Dim DeskhWnd As Long, DeskDC As Long
    DeskhWnd& = GetDesktopWindow()
    DeskDC& = GetDC(DeskhWnd&)
    
    picMain.ScaleMode = vbPixels
    BitBlt picMain.hDC, 0&, 0&, picMain.ScaleWidth, picMain.ScaleHeight, DeskDC&, 0&, 0&, SRCCOPY
    
    End Sub
    in the code on the webpage it said

    Code:
    BitBlt Form1.hDC, 0&, 0&, Screen.Width, Screen.Height, DeskDC&, 0&, 0&, SRCCOPY
    but I've tried changing the Form1.hDC to picMain.hDC to get the app to put an image of the desktop into a picture box instead of onto the form, but it won't! It just keeps the picture box looking plain and gray. Is there anyone who can point me in the right direction???

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If you haven't done so set the AutoRedraw property of the picture box to True.

  3. #3
    Guest
    this works for me

    Code:
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    
    Private Sub Command1_Click()
        BitBlt Picture1.hDC, 0, 0, 10, 20, Picture2.hDC, 0, 0, vbSrcCopy
    End Sub

    the scalemodes are set to pixel, and picture2 autoredraw is true, picture1 autoredraw is false.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Cool thanx

    Cheers guys - autoredraw set to false - problem solved

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