Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42225

Why doesn't this screencap program work?

$
0
0
I have a form with two small picture boxes and one command button. Each of which won't be able to display the whole desktop screen, but should show enough as to be able to determine if the screencap APIs are working properly. One is based on using GetDesktopWindow, in conjuction with GetDC, and the other uses GetWindowDC. These API calls fail miserably though. They ALWAYS produce a black image!

Below is the code I'm using.
Code:

Private Declare Function GetDesktopWindow Lib "user32" () 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
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long


Private Sub Command1_Click()
Dim a As Long
Dim b As Long

a = GetDesktopWindow
b = GetDC(a)
BitBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, b, 0, 0, vbCopyPen
ReleaseDC a, b
Picture1.Refresh


a = GetDesktopWindow
b = GetWindowDC(a)
BitBlt Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, b, 0, 0, vbCopyPen
ReleaseDC a, b
Picture2.Refresh

End Sub


Viewing all articles
Browse latest Browse all 42225

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>