Link to home
Start Free TrialLog in
Avatar of msali
msali

asked on

Capture Screen Image???

Hi experts,
I am trying to make an application in which i want to capture the screen image of whatever is placed on the screen behind my application.  I have tried to use the BitBlt function but since i do not have any documentation on it i am unable to use it - can anyone give me a sample code of capturing the screen image.  Also is it possible to save that image in .bmp or .jpg format so that anyone on the net can read it and display it on their own screen.

A very quick response will be much appriciated since i am getting extrememly close to my deadline.
Thanks.
Avatar of woka
woka

This is not what you asked for, but may be useful anyway.  If you press Alt-PrintScreen, a copy of the currently active window is copied to the clipboard.
ASKER CERTIFIED SOLUTION
Avatar of SGC
SGC

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of msali

ASKER

Apparantly it looks good but I will try it for vb5 tonight and let u know tomorror.
in the mean time if u have a vb5 code let me know i will be greatful.
thanks.
msa
The only thing you'll need to do to make this work is update the API's to their 32 bit equivilants...

Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (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

Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Declare Sub GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long

Avatar of msali

ASKER

Yes i had it done thanks a lot any way.
Now the the last part of my question how to save it as a .bmp or .jpg file.
After using the BitBlt function i tried to place it in the clipboard by using the API calls to
OpenClipboard
EmptyClipboard
SetClipboardData
CloseClipboard
but when i use the SetclipboardData i get an error telling me that it cannot find entry point in DLL using "SetclipboardDataA"
SetClipboardData hSrcDC&, vbCFDIB - boom Errorr

btw: after bitblt i cannot access the picture1.picture or picture1.image if i want to shift or move them in a different picturebox or imagebox

and yes i will increase the points if answered

Thanks again and in advance.
msali

Use SavePicture to save the image as a BMP to a specified path, and then just do a LoadPicture on that new BMP. Kind of sneaky, but it works.
Avatar of msali

ASKER

Acutally it does not work - atleast for me.
After bitblt the image is pasted on the device Context DC.
I tried the following:
SavePicture me.image, "c:\temp\mybmp.bmp"

Listed below is my code see if u can debug for me (thanks)

Sub Load_Form()
hWndSrc& = GetDesktopWindow()
    hSrcDC& = GetDC(hWndSrc&)
    GetWindowRect hWndSrc&, WinSize
    xSrc& = 0
    ySrc& = 0
    nWidth& = WinSize.Right
    nHeight& = WinSize.Bottom
   
    hDestDC& = Form1.hdc
    xDest& = 0
    yDest& = 0
   
    GetTwipsPerPixel
   
    dwRop& = &HCC0020
   
    Tmp& = BitBlt(hDestDC&, xDest&, yDest&, nWidth&, nHeight&, hSrcDC&, xSrc&, ySrc&, dwRop&)
    Tmp& = ReleaseDC(hWndSrc&, hSrcDC&)
   
End Sub
Avatar of msali

ASKER

Sorry, I forgot to mention that after applying tbe bitblt and before relleasedc i have the savepicture statement.  It does create bitmap file but blank - all grey color not the actual captured image.

thanks again
Avatar of msali

ASKER

Try blting into a picture box rather than onto the form.
Avatar of msali

ASKER

Same result with picturebox also.

thanks
Any way i got it done by manually coping the DC to the disk.

thanks a lot