关于API获取粘贴板的问题,希望VB或C的高手进来看看,谢谢了
capCreateCaptureWindowA这个API可以获得摄像头的图像。用SendMessageVideoHwnd,WM_CAP_EDIT_COPY,0,0'截图到...
capCreateCaptureWindowA这个API可以获得摄像头的图像。
用SendMessage VideoHwnd, WM_CAP_EDIT_COPY, 0, 0 '截图到剪贴板
然后我打开WIN自带的画图,粘贴时,确实粘贴进去了图像,证明粘贴板中存在的是图像。
然而我用代码:
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function AbortDoc Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GetEnhMetaFileBits Lib "gdi32" (ByVal hEMF As Long, ByVal cbBuffer As Long, lpbBuffer As Byte) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const CF_UNICODETEXT = 13
Private Const CF_DIB = 8
Private Const CF_DIF = 5
-----------
If IsClipboardFormatAvailable(2) = 1 Then
Dim lpData As Long
Dim nSize As Long
Dim hMem As Long
Dim n As Long
OpenClipboard ByVal 0&
hMem = GetClipboardData(2)
lpData = GlobalLock(hMem)
nSize = GlobalSize(lpData)
MsgBox nSize
's = String(nSize, 0)
'n = GetEnhMetaFileBits(hMem, 0, ByVal 0&)
ReDim img_byt(921653)
CopyMemory img_byt(0), ByVal hMem, 921654
GlobalUnlock hMem
CloseClipboard
End If
上面的代码并不能得到粘贴板中关于图片的数据,代码显的有点凌乱,我乱试了一通,不是内存读写错误就是得到一个空数据,请高手指点一下。谢谢了 展开
用SendMessage VideoHwnd, WM_CAP_EDIT_COPY, 0, 0 '截图到剪贴板
然后我打开WIN自带的画图,粘贴时,确实粘贴进去了图像,证明粘贴板中存在的是图像。
然而我用代码:
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function AbortDoc Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GetEnhMetaFileBits Lib "gdi32" (ByVal hEMF As Long, ByVal cbBuffer As Long, lpbBuffer As Byte) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const CF_UNICODETEXT = 13
Private Const CF_DIB = 8
Private Const CF_DIF = 5
-----------
If IsClipboardFormatAvailable(2) = 1 Then
Dim lpData As Long
Dim nSize As Long
Dim hMem As Long
Dim n As Long
OpenClipboard ByVal 0&
hMem = GetClipboardData(2)
lpData = GlobalLock(hMem)
nSize = GlobalSize(lpData)
MsgBox nSize
's = String(nSize, 0)
'n = GetEnhMetaFileBits(hMem, 0, ByVal 0&)
ReDim img_byt(921653)
CopyMemory img_byt(0), ByVal hMem, 921654
GlobalUnlock hMem
CloseClipboard
End If
上面的代码并不能得到粘贴板中关于图片的数据,代码显的有点凌乱,我乱试了一通,不是内存读写错误就是得到一个空数据,请高手指点一下。谢谢了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询