VB PrintWindow 怎么后台取色
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 '获取图片数据
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal HDC As Long) As Long '释放DC
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function PrintWindow Lib "user32" (ByVal SrcHwnd As Long, ByVal DesHDC As Long, ByVal uFlag As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal HDC As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal HDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal HDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal HDC As Long, ByVal hObject As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Dim intX As Long
Dim intY As Long
Dim intZ As Long
'颜色表
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbAlpha As Byte '透明通道
End Type
Private 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
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
'图片文件头
Dim BI As BITMAPINFO
Dim BI1 As BITMAPINFO
Public Function GetColor(BKNG, x, y)
Dim fPic() As Byte
Dim lngHei As Long, lngWid As Long
lngHei = Screen.Height
lngWid = Screen.width
With BI1.bmiHeader
.biSize = Len(BI1.bmiHeader)
.biWidth = lngWid
.biHeight = -lngHei
.biBitCount = 32
.biPlanes = 1
End With
ReDim fPic(3, 100 - 1, 100 - 1)
Dim hBMPhDC, hDCmem As Long, Pic1Handle As Long, hBmpPrev As Long, Cor
PrintWindow BKNG, hBMPhDC, 0
hDCmem = CreateCompatibleDC(hBMPhDC)
Pic1Handle = CreateCompatibleBitmap(hBMPhDC, lngWid, lngHei)
hBmpPrev = SelectObject(hDCmem, Pic1Handle)
BitBlt hDCmem, 0, 0, lngWid, lngHei, hBMPhDC, 0, 0, SRCCOPY
DeleteDC hDCmem
i = GetDIBits(hBMPhDC, Pic1Handle, 0, lngHei, fPic(0, 0, 0), BI1, 0)
ReleaseDC BKNG, hBMPhDC
Cor = RGB(fPic(2, x, y), fPic(1, x, y), fPic(0, x, y))
DeleteObject hBmpPrev
GetColor = Hex(Cor)
End Function
我研究了两三天怎么一直取不到后台的颜色,希望有大神可以指点一下,实在没办法才来的,不是伸手党