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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
Option Explicit
'je les met en constante afin de ne pas avoir a metre les Guillemets quand on l'injecte en argument dans l'apel a la fonction
Public Const blueseven = "blueseven"
Public Const wood = "wood"
Public Const blood = "blood"
Public Const darkblue = "darkblue"
Public Const lady = "lady"
Public Const XPcorporate = "XPcorporate"
Public Const vista = "vista"
Public Const XP = "XP"
Public Const vertical = "vertical"
Public Const silver = "silver"
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(8) As Byte
End Type
Public Type PICTDESC
cbSize As Long
picType As Long
hImage As Long
End Type
Public Declare Function OpenClipboard& Lib "User32" (ByVal hwnd As Long)
Public Declare Function EmptyClipboard Lib "User32" () As Long
Public Declare Function GetClipboardData& Lib "User32" (ByVal wFormat%)
Public Declare Function SetClipboardData Lib "User32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Public Declare Function CloseClipboard& Lib "User32" ()
Public Declare Function CopyImage& Lib "User32" (ByVal handle&, ByVal un1&, ByVal n1&, ByVal n2&, ByVal un2&)
Public Declare Function IIDFromString Lib "ole32" (ByVal lpsz As String, ByRef lpiid As GUID) As Long
Public Declare Function OleCreatePictureIndirect Lib "olepro32" (pPictDesc As PICTDESC, ByRef riid As GUID, ByVal fOwn As Long, ByRef ppvObj As IPicture) As Long
Public slider As Object
Public largeur As Long
Public hauteur As Long
Public maform As Object
Public iPic As IPicture
Public sens As Variant
'Public fin As Long
Public i As Long
Public e As Long
Dim couleur_slider As Variant
Dim couleur_cadre As Variant
Function Progressbarre(e, fin)
On Error Resume Next
If sens = vertical Then
slider.Height = (hauteur / fin) * e
slider.Top = maform.fondprogress.Top + (hauteur - (hauteur / fin) * e) + 1 '(fondprogress.Top + fondprogress.Height - 2) + difference
ElseIf sens <> vertical Then slider.Width = (largeur / fin) * e
End If
DoEvents ' ne pas oublié de mettre ce doevents sinon l'effet est trop rapide
On Error GoTo 0
End Function
'on prend un cliché on en fait un bitmap
Public Function progress_bar_perso(usf, Optional le_style As String = "vista")
Set maform = usf
maform.fondprogress.Caption = ""
maform.fondprogress.BackStyle = 0 'on rend transparent le label fondprogress
'si fondprogress est moins haut que largealors ce sera le mode horizontal sinon vertical
sens = IIf(usf.fondprogress.Height < maform.fondprogress.Width, "horizontal", "vertical")
' on memorise la largeur et hauteur variable qui vont nous servir a manipuler le "Slider "
largeur = maform.fondprogress.Width - 2
hauteur = maform.fondprogress.Height - 2
' au cas ou progress existerait deja on la vire du sheet
Dim shapo As Shape
For Each shapo In ActiveSheet.Shapes
If shapo.Name = "progress" Then shapo.Delete
Next
'on ajoute une forme dans le sheets( provisoirement)
With ActiveSheet.Shapes.AddShape(1, 10, 15, maform.fondprogress.Width + 100, maform.fondprogress.Height + 100)
.Name = "progress"
.Line.Visible = msoFalse
.Fill.Visible = msoTrue
'8 styles sont disponibles
Select Case le_style
Case XP
.Fill.ForeColor.RGB = RGB(Red:=0, Green:=255, Blue:=30)
Case vista
.Fill.ForeColor.RGB = RGB(Red:=60, Green:=230, Blue:=100)
couleur_slider = vbBlack
couleur_cadre = 4210688
Case XPcorporate
.Fill.ForeColor.RGB = RGB(Red:=200, Green:=255, Blue:=255)
couleur_slider = vbWhite
couleur_cadre = vbBlack
Case lady
.Fill.ForeColor.RGB = RGB(Red:=255, Green:=100, Blue:=200)
couleur_slider = &HFF80FF
couleur_cadre = &HC0C0FF
Case darkblue
.Fill.ForeColor.RGB = RGB(Red:=100, Green:=120, Blue:=180)
couleur_slider = vbBlue
couleur_cadre = 8388736
Case blood
.Fill.ForeColor.RGB = RGB(Red:=255, Green:=0, Blue:=0)
couleur_slider = &HC0&
couleur_cadre = 8388736
Case silver
.Fill.ForeColor.RGB = RGB(Red:=255, Green:=255, Blue:=255)
'.Fill.PresetTextured 1
couleur_slider = vbBlack
couleur_cadre = vbWhite
Case wood
.Fill.PresetTextured 23
couleur_slider = vbBlack
couleur_cadre = &H40C0&
If sens = vertical Then .Rotation = 90
GoTo suite ' on saute l'etape du gradient puisque l'on a une texture
Case blueseven
.Fill.ForeColor.RGB = RGB(Red:=0, Green:=200, Blue:=255)
couleur_slider = vbWhite
couleur_cadre = vbBlue
Case le_style
.Fill.PresetTextured le_style
couleur_slider = vbWhite
couleur_cadre = vbBlack
End Select
If Not IsNumeric(le_style) Then
'l 'effet tube sera vertical ou horizontal selon "sens"
If sens = "vertical" Then
.Fill.OneColorGradient msoGradientVertical, 4, 0.1
ElseIf sens <> "vertical" Then .Fill.OneColorGradient msoGradientHorizontal, 4, 0.1
End If
End If
End With
suite:
'on copie la forme dans le clipboard
ActiveSheet.Shapes("progress").CopyPicture xlScreen, xlBitmap 'copie la selection dans le clipboard
'prend l'image dans le cliboard
Dim hCopy&: OpenClipboard 0&
hCopy = CopyImage(GetClipboardData(2), 0, 0, 0, &H8)
CloseClipboard ' ferme le cliboard
If hCopy = 0 Then Exit Function 'si il y a rien on sort de la fonction
Const IPictureIID = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"
Dim tIID As GUID, tPICTDEST As PICTDESC, Ret As Long
Ret = IIDFromString(StrConv(IPictureIID, vbUnicode), tIID)
If Ret Then Exit Function
With tPICTDEST
.cbSize = Len(tPICTDEST)
.picType = 1
.hImage = hCopy
End With
'on créé le itmap
Ret = OleCreatePictureIndirect(tPICTDEST, tIID, 1, iPic)
If Ret Then Exit Function
On Error GoTo 0
'on ajoute le control image dans le userform a l'interieur du label "fondprogress"
Set slider = usf.Controls.Add("Forms.Image.1", "PROGRESSBARRE", True)
'on ajuste le slider en fonction du fondprogress et en fonction du sens determiné au depart de la fonction sur la condition _
du width et du height de celui ci
With slider
.Left = usf.fondprogress.Left + 1
.Top = IIf(sens = "vertical", maform.fondprogress.Top + maform.fondprogress.Height - 2, maform.fondprogress.Top + 1)
.Width = IIf(sens = "vertical", maform.fondprogress.Width - 2, 1)
.Height = IIf(sens = "vertical", 1, maform.fondprogress.Height - 2)
.Picture = iPic
.PictureSizeMode = 1
.BorderColor = couleur_slider
End With
maform.fondprogress.BorderColor = couleur_cadre
'on efface la forme provisoire que l'on a créé precedemant dans la feuille on en a plus besoin
ActiveSheet.Shapes("progress").Delete
' on vide la memoire de ipic on en a plus besoins non plus 'limage est copiée dans le controlimage (slider)
Set iPic = Nothing
End Function |
Partager