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 65 66 67 68 69 70 71
|
Option Explicit
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "User32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwFlags As Long) As Long
Private Declare Function FindWindowA Lib "User32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "User32" (ByVal hwnd As Long) As Long
'pouvoir le deplacer
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "User32" () As Long
'api pour capture basic
Private Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function IsClipboardFormatAvailable Lib "User32" (ByVal wFormat As Integer) As Long
Dim cl As New snapshot
Public WithEvents forme As UserForm
Private Nnom As String
Private nhandle As Long
Private Nusf As UserForm
Property Get handle() As Long: handle = nhandle: End Property ' Propriété en lecture
Property Let handle(handle As Long): nhandle = handle: End Property ' Propriété en écriture
Property Get nom() As String: nom = Nnom: End Property ' Propriété en lecture
Property Let nom(nom As String): Nnom = nom: End Property ' Propriété en écriture
'ici ca ne fonctionne pas pour l'usf
Property Get usf() As UserForm: Set usf = Nusf: End Property ' Propriété en lecture
Property Let usf(usf As UserForm): End Property ' Propriété en écriture
Sub Select_ZoneCapture()
Dim handle As Long, maform
Set maform = ThisWorkbook.VBProject.VBComponents.Add(3)
VBA.UserForms.Add (maform.Name)
Set maform = UserForms(UserForms.Count - 1)
maform.Show 0: maform.BackColor = vbRed
handle = FindWindowA(vbNullString, maform.Name) 'Recupere le handle de la fenêtre
SetWindowLong handle, -16, &H94080080: SetWindowLong handle, -20, &H0: DrawMenuBar handle ' sans caption
SetWindowLong handle, -20, &H80000 'pour ajouter l'attribut transparent à la fenêtre on prend en compte la totalite de sa surface
SetLayeredWindowAttributes handle, 0, 60, &H2 'Definie la transparence de la fenêtre dans l'argumen(3) de 0 à 255
SetWindowPos handle, -1, 0&, 0&, 0&, 0&, (&H1 Or &H2) 'reste toujours en premier plan
'intégration de l'userform et son non et son handle dans les variable de la classe
Set cl.forme = maform
cl.handle = handle
cl.nom = maform.Name
'Set cl.usf = maform
End Sub
Private Sub forme_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ReleaseCapture
SendMessage handle, &HA1, 2, 0&
End Sub
Private Sub forme_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim hPicAvail
With CreateObject("htmlfile").parentwindow.clipboardData.clearData("Text"): End With
'Definie la transparence de la fenêtre dans l'argumen(3) de 0 à 255 ici completement transparent
SetLayeredWindowAttributes handle, 0, 0, &H2
'capture
keybd_event &H2C, 1, 0, 0: keybd_event &H2C, 1, &H2, 0 'on appuie et on relache la touche snapshot
'on va boucler tant que le contenu du clipboard n'est pas BITMAP soit (2) le temps necessaire a ce que
'la touche print excecute sa tache et envoie les informations au clipboard
Do: DoEvents: hPicAvail = IsClipboardFormatAvailable(2): Loop While hPicAvail = 0 'Or (Timer - T) > 1000
'l'object forme(userform) ne gere pas le width et height dans un module classe
'comment faire???
'crée un graphique
' With ActiveSheet.ChartObjects.Add(0, 0, forme.Width, forme.Height)
'.Chart.Paste: ' .Chart.Export chemin, "jpg" 'colle l'image dans graphique puis exportation le graphique en image jog
'.Delete
'End With
ActiveSheet.Paste
Unload forme
On Error Resume Next
With ThisWorkbook.VBProject.VBComponents: .Remove .Item(nom): End With
On Error GoTo 0
End Sub |