AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

Copying the desktop image to a Form

This tip demonstrates how to copy the image of the desktop onto a form using the BitBlt function.  This tip could be used in screen grabbing software, or even as a screen saver.

Module Code

Add the following code to a module:

Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hSrcDC As Integer, ByVal xSrc As Integer, _
ByVal ySrc As Integer, ByVal dwRop As _
Long) As Integer

Declare Function GetDesktopWindow Lib "user32" () As Long

Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long

Public Const SRCCOPY = &HCC0020
Public Const SRCAND = &H8800C6
Public Const SRCINVERT = &H660046

Form Code

Set the Form properties to the following:




0 - None


2 - Maximized

Now, add the following code to the form:

Private Sub Form_Load()

Dim DeskhWnd As Long, DeskDC As Long

'Get the hWnd of the desktop
DeskhWnd& = GetDesktopWindow()

'BitBlt needs the DC to copy the image. So, we
'need the GetDC API.
DeskDC& = GetDC(DeskhWnd&)

BitBlt Form1.hDC, 0&, 0&, _
Screen.Width, Screen.Height, DeskDC&, _
0&, 0&, SRCCOPY

End Sub

Add a command button to the form with following code:

Private Sub Command1_Click()
Unload Me
End Sub 




Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at