Hey Guys ,
Anyone know how I can capture a form as a bitmap in code ?
Thanks ,
[]P
Printable View
Hey Guys ,
Anyone know how I can capture a form as a bitmap in code ?
Thanks ,
[]P
Try this:
Code:Private Declare Function SetForegroundWindow _
Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_SNAPSHOT = &H2C
Public Function SaveScreen(ByVal theFile As String) As Boolean
On Error Resume Next
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
SavePicture Clipboard.GetData(vbCFBitmap), theFile
SaveScreen = True
Exit Function
End Function
Usage
Private Sub Command1_Click()
SetForegroundWindow Me.hWnd
Call SaveScreen("C:\Windows\Desktop\MyForm.bmp")
End Sub
Hey Matt ,
Thanks for the response . I'd like to just BitBlt it into a picturebox . Sorry I changed my mind , this way would have less overhead I believe . Although something is wrong with the code below . My goal is to get an image of frm_Main into a picture box that is used as a priview window . It runs all the way though but leaves the picture box empty . Do you see why ?
Am I going about this the right way ?Code:Picture1.AutoRedraw = True
Dim frmDC As Long
frmDC = frm_Main.hDc
BitBlt Picture1.hDc, 0, 0, 0, 0, frmDC, 0, 0, SRCCOPY
Picture1.Refresh
[]P