|
Option Explicit
Public Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Public Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Public Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Public Declare Function CreateDIBSection Lib "gdi32" ( _
ByVal hdc As Long, pBitmapInfo As BITMAPINFO, _
ByVal un As Long, ByVal lplpVoid As Long, _
ByVal handle As Long, ByVal dw As Long) As Long
Public Declare Function GetWindowRect Lib "user32" ( _
ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hdc As Long) As Long
Public 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
Public Declare Function CreateCompatibleDC Lib "gdi32" ( _
ByVal hdc As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" ( _
ByVal hdc As Long) As Long
Public Declare Function SelectObject Lib "gdi32" ( _
ByVal hdc As Long, ByVal hObject As Long) As Long
Function CreateBMPFromWindow(Form_hwnd As Long) As Long
Dim rc As RECT
Dim X As Integer
Dim Y As Integer
Dim cx As Integer
Dim cy As Integer
Dim hdcScreen As Long
Dim hdcMemory As Long
Dim Bitmap As Long
GetWindowRect Form_hwnd, rc
X = rc.Left
Y = rc.Top
cx = rc.Right - rc.Left
cy = rc.Bottom - rc.Top
hdcScreen = GetDC(0)
hdcMemory = CreateCompatibleDC(0)
Bitmap = CreateDibBMP(hdcScreen, cx, cy, 16)
SelectObject hdcMemory, Bitmap
BitBlt hdcMemory, 0, 0, cx, cy, hdcScreen, X, Y, vbSrcCopy
DeleteDC hdcMemory
ReleaseDC 0, hdcScreen
CreateBMPFromWindow = Bitmap
End Function
Function CreateDibBMP(hdc As Long, _
ByVal w As Long, ByVal h As Long, _
bpp As Integer) As Long
Dim bih As BITMAPINFO
bih.bmiHeader.biSize = 40
bih.bmiHeader.biWidth = w
bih.bmiHeader.biHeight = h
bih.bmiHeader.biBitCount = bpp
bih.bmiHeader.biPlanes = 1
bih.bmiHeader.biCompression = 0
bih.bmiHeader.biSizeImage = 0
bih.bmiHeader.biClrUsed = 0
CreateDibBMP = CreateDIBSection(hdc, bih, 0, 0, 0, 0)
End Function
|
|