Results 1 to 3 of 3

Thread: Placing graphic in clipboard to screen?

  1. #1

    Thread Starter
    Member sTyLeZ's Avatar
    Join Date
    Jan 2001
    Posts
    35

    Placing graphic in clipboard to screen?

    Ok...I have found 1000's of pages with info on how to copy the screen, the whole screen and nothing but the screen (well, bitmaps too) to the clipboard. But I can't find a single thing about putting what is in the clipboard BACK onto the screen.

    What I did was modify some code which created a transparent bmp and placed it on the clipboard. Now I want to put that modified bmp back onto the screen. How can I do this? Does the clipboard have a DC that I can get somehow?
    Now the world is gone I'm just one...

  2. #2

    Thread Starter
    Member sTyLeZ's Avatar
    Join Date
    Jan 2001
    Posts
    35
    Ok...I've got it so I can put images to the screen, save them as jpgs and whatnot. Now, my problem lies within starcraft. I'm trying to capture images from the game without using its whole screen capture, but they're coming out extremely dark...like completely black 99% of the time. I tried capturing in Counter-Strike, and the images came out fine.

    Any ideas? Is SC just so old and screwed up that it doesn't like external programs capturing it, or what?

    Here is the function I use to get an image:

    Code:
    Public Function xGet(ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long) As IPictureDisp
    
        Dim targetDC As Long
        Dim hdc As Long
        Dim tempPict As Long
        Dim oldPict As Long
        Dim wndWidth As Long
        Dim wndHeight As Long
        Dim Pic As PICTDESC
        Dim rcWindow As RECT
        Dim guid(3) As Long
       
        ' provide the right handle for the desktop window
        If hwnd = 0 Then hwnd = GetDesktopWindow
        
        ' get window's size
        GetWindowRect hwnd, rcWindow
        wndWidth = Width
        wndHeight = Height
        ' get window's device context
        targetDC = GetWindowDC(hwnd)
        
        ' create a compatible DC
        hdc = CreateCompatibleDC(targetDC)
       
        ' create a memory bitmap in the DC just created
        ' the has the size of the window we're capturing
        tempPict = CreateCompatibleBitmap(targetDC, wndWidth, wndHeight)
        oldPict = SelectObject(hdc, tempPict)
        
        ' copy the screen image into the DC
        BitBlt hdc, 0, 0, wndWidth, wndHeight, targetDC, x, y, vbSrcCopy
       
       ' set the old DC image and release the DC
        tempPict = SelectObject(hdc, oldPict)
        DeleteDC hdc
        ReleaseDC GetDesktopWindow, targetDC
       
        ' fill the ScreenPic structure
        With Pic
            .cbSize = Len(Pic)
            .pictType = 1           ' means picture
            .hIcon = tempPict
            .hPal = 0           ' (you can omit this of course)
        End With
      
        ' convert the image to a IpictureDisp object
        ' this is the IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
        ' we use an array of Long to initialize it faster
        guid(0) = &H7BF80980
        guid(1) = &H101ABF32
        guid(2) = &HAA00BB8B
        guid(3) = &HAB0C3000
        ' create the picture,
        ' return an object reference right into the function result
        OleCreatePictureIndirect Pic, guid(0), True, xGet
    
    End Function
    Then in my form when the button is pressed, I have this:

    Code:
    Private Sub getImage_Click()
        
        Dim wide, high As Long
        Dim x, y As Long
        wide = CLng(txtWidth.Text)
        high = CLng(txtHeight.Text)
        x = CLng(txtX.Text)
        y = CLng(txtY.Text)
        Picture1 = xGet(CLng(lblHandle.Caption), x, y, wide, high)
        
    End Sub
    
    Private Sub saveImage_Click()
        
        Dim cdibpic As New cDIBSection
        Dim FileName As String
        FileName = "test.jpg"
        cdibpic.CreateFromPicture Picture1.Picture
        SaveJPG cdibpic, FileName, 70
    
    End Sub
    Now the world is gone I'm just one...

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You would need a lot of APIs to do that (I think ), but you can try bitblting it to a picturebox and then using Clipboard.SetData to copy the image
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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