1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Option Explicit
Const WM_CAP As Long = &H400
Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Long = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Long = WM_CAP + 30
Const WM_CAP_SET_PREVIEW As Long = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE = WM_CAP + 52
Const WM_CAP_SET_SCALE = WM_CAP + 53
Const WM_CAP_GRAB_FRAME_NOSTOP = WM_CAP + 61
Const WM_CLOSE = &H10
Const WM_QUIT = &H12
Const WS_VISIBLE As Long = &H10000000
Const conhwndtopmost = -1
Const conhwndnotopmost = -2
Const conswpnoactivate = &H10
Const conswpshowwindow = &H40
Dim hwnd As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal nID As Long) As Long
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Long, ByVal lpszName As String, ByVal cbName As Long, ByVal lpszVer As String, ByVal cbVer As Long) As Boolean
Declare Function setwindowpos Lib "user32" (ByVal hwnd As Long, ByVal hwndinsertafter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long) As Long
Sub WebCamClip()
If hwnd = 0 Then
hwnd = capCreateCaptureWindowA("BlaBla dont", WS_VISIBLE, 0, 0, 200, 200, GetDesktopWindow(), 0)
SendMessage hwnd, WM_CAP_DRIVER_CONNECT, 0, 0
SendMessage hwnd, WM_CAP_SET_PREVIEWRATE, 30, 0
SendMessage hwnd, WM_CAP_SET_SCALE, 1, 0
SendMessage hwnd, WM_CAP_SET_PREVIEW, 1, 0
SendMessage hwnd, WM_CAP_GRAB_FRAME_NOSTOP, 0, 0
End If
SendMessage hwnd, WM_CAP_EDIT_COPY, 640, 480
setwindowpos hwnd, conhwndtopmost, 0, 0, 0, 0
End Sub
Sub Capturer()
'effectue la capture d'image
WebCamClip
With Worksheets("Work")
If .ChartObjects.Count = 0 Then
.ChartObjects.Add(0, 0, 480, 320).Chart.Paste
Else
.ChartObjects(1).Chart.Paste
End If
End With
setwindowpos hwnd, conhwndtopmost, 0, 0, 0, 0
End Sub
'Obligatoire pour fermer la cam
Sub Fermer()
If hwnd <> 0 Then
SendMessage hwnd, WM_CAP_DRIVER_DISCONNECT, 0, 0
SendMessage hwnd, WM_CLOSE, 0, 0
SendMessage hwnd, WM_QUIT, 0, 0
hwnd = 0
End If
End Sub |
Partager