好啊,那真谢谢了!Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long private Cache() as bytePrivate Sub Command1_Click() 'Dim WinDeskHwnd As Long, WinDeskHdc As Long WinDeskHwnd = GetDesktopWindow WinDeskHdc = GetDC(WinDeskHwnd) '出错陷阱 If WinDeskHdc = 0 Then Debug.Print "GetWindowsDesktopHdc Error!": Exit Sub '现在要把这个WinDeskHdc中的内容复制到Cache()数组中, '只要告诉我怎么复制就可以了,非常感谢End Sub
Cache()数组的具体格式? 24位?
…… If WinDeskHdc = 0 Then Debug.Print "GetWindowsDesktopHdc Error!": Exit Subdim hDIBDC as Long Dim hDIBOldMap as long Dim bi as BITMAPINFOHEADER Dim hDIB as long dim pDIB as longhDIBDC=CreateCompatibleDC(WinDeskHdc) If hDIBDC=0 then Exit SubWith bi .biSize=len(bi) .biWidth=Screen.Width\Screen.TwipsPerPixelX .biHeight=Screen.Height\Screen.TwipsPerPixelY .bibitCount=24 .biPlanes=1 .biCompression=BI_RGB .biSizeImage=((.biWidth*3+3)and &H7FFFFFFC)*.biHeight End With hDIB=CreateDIBSection(hDIBDC, bi, DIB_RGB_COLORS, pDIB,0,0) hDIBOldMap=SelectObject(hDIBDC,hDIB)'由于是DIBSection,可以直接用BitBlt BitBlt hDIBDC, 0, 0, bi.biWidth, bi.biHeight, WinDeskHdc, 0, 0, vbSrcCopyReDim Cache(0 to bi.biSizeImage-1) as Byte CopyMemory Cache(0), byval pDIB, bi.biSizeImage 对Cache进行操作 Call SelectObject(hDIBDC, hDIBOldMap) DeleteDC hDIBDC
注意CreateDIBSection的声明 APIViewer 2003的是错误的应该这样: Public Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, lpbmi As Any, ByVal iUsage As Long, ByRef ppvBits As Long, ByVal hSection As Long, ByVal dwOffset As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
private Cache() as bytePrivate Sub Command1_Click()
'Dim WinDeskHwnd As Long, WinDeskHdc As Long
WinDeskHwnd = GetDesktopWindow
WinDeskHdc = GetDC(WinDeskHwnd)
'出错陷阱
If WinDeskHdc = 0 Then Debug.Print "GetWindowsDesktopHdc Error!": Exit Sub
'现在要把这个WinDeskHdc中的内容复制到Cache()数组中,
'只要告诉我怎么复制就可以了,非常感谢End Sub
24位?
If WinDeskHdc = 0 Then Debug.Print "GetWindowsDesktopHdc Error!": Exit Subdim hDIBDC as Long
Dim hDIBOldMap as long
Dim bi as BITMAPINFOHEADER
Dim hDIB as long
dim pDIB as longhDIBDC=CreateCompatibleDC(WinDeskHdc)
If hDIBDC=0 then Exit SubWith bi
.biSize=len(bi)
.biWidth=Screen.Width\Screen.TwipsPerPixelX
.biHeight=Screen.Height\Screen.TwipsPerPixelY
.bibitCount=24
.biPlanes=1
.biCompression=BI_RGB
.biSizeImage=((.biWidth*3+3)and &H7FFFFFFC)*.biHeight
End With
hDIB=CreateDIBSection(hDIBDC, bi, DIB_RGB_COLORS, pDIB,0,0)
hDIBOldMap=SelectObject(hDIBDC,hDIB)'由于是DIBSection,可以直接用BitBlt
BitBlt hDIBDC, 0, 0, bi.biWidth, bi.biHeight, WinDeskHdc, 0, 0, vbSrcCopyReDim Cache(0 to bi.biSizeImage-1) as Byte
CopyMemory Cache(0), byval pDIB, bi.biSizeImage
对Cache进行操作
Call SelectObject(hDIBDC, hDIBOldMap)
DeleteDC hDIBDC
APIViewer 2003的是错误的应该这样:
Public Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, lpbmi As Any, ByVal iUsage As Long, ByRef ppvBits As Long, ByVal hSection As Long, ByVal dwOffset As Long) As Long
Call SelectObject(hDIBDC, hDIBOldMap)
DeleteObject hDIB
DeleteDC hDIBDC