Taking a screenshot of an invisible form
I've been reading up on the conventional ways to take screenshots of normal forms, using the keybd_event api call.
What I would like to do is take a screenshot of an invisible form. This screenshot will be available on the company intranet through a web page. Does anyone have any ideas? or is this impossible..
Many thanks, and regards
# 5 Re: Taking a screenshot of an invisible form
Just thought I'd give you some extra help on this one:
If you want to keep it hidden all the time, you can use BitBlt to capture the form:
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
BitBlt Picture1.hdc, 0, 0, 1024, 768, Form1.hDC, 0, 0, vbSrcCopy
Then use the picturebox to save the image to file.
Also, a lot of people ask how to do a printscreen without the buggy method of key emulation. Here's my code:
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
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
BitBlt Picture1.hdc, 0, 0, 1024, 768, GetDC(GetDesktopWindow()), 0, 0, vbSrcCopy
Also, in both cases, make sure the picturebox's AutoRedraw is set to false, I don't know why, but it seems to stop the code from doing its job.
Hope it's useful!
# 6 Re: Taking a screenshot of an invisible form
Seems to me, that if you can give the info as text, you would be better off just writing it to a file. Then you'd save all the bandwidth of an image.
Of course, if you don't have the source code, then you'd have to capture the image. In addition to what Burningmace posted, I'd suggest using GetWindowRect, and use the coordinates for BitBlt. That way, you would only be capturing the image of the window you want, instead of the entire screen. Also, don't forget to use ReleaseDC afterward, otherwise you'll have a memory leak.
It may be helpful to use SetWindowPos to bring up the window, and you could use the hWnd of the window to get a DC for it instead of the entire screen. Then you could use GetClientRect instead, which will help cut down the size of the image, since it leaves out the size of the titlebar. There are threads on how to save an image to jpg as well, which will greatly reduce bandwidth requirements.
In any case, you may find it necessary to use UpdateWindow to make it show up before using BitBlt. There may also be the need for DoEvents in there too.