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
|
Function menu(boutons, bt, Optional mode As String = "")
Dim i As Long, Barre As CommandBar, pop, e As Long, decal As Long, r As RECT, XX, YiN As Long, HdC As Long, EpS, lpppX As Long, lpppy As Long, YY As Long
On Error GoTo suite
delmenu
suite:
HdC = GetDC(0): lpppX = GetDeviceCaps(HdC, LOGPIXELSX): lpppy = GetDeviceCaps(HdC, LOGPIXELSY)
Set Barre = CommandBars.Add("MenuUSF", msoBarPopup, False, True)
For i = 0 To UBound(boutons)
If IsArray(boutons(i)) Then
Set pop = Barre.Controls.Add(msoControlPopup, 1, , , True): pop.Caption = boutons(i)(UBound(boutons(i)))
pop.Caption = boutons(i)(UBound(boutons(i)))
For e = 0 To UBound(boutons(i)) - 1
With pop.Controls.Add(msoControlButton, 1, , , True)
.Caption = Split(boutons(i)(e), ":")(0)
.FaceId = Split(boutons(i)(e), ":")(1)
.Enabled = Val(Split(boutons(i)(e), ":")(2))
.OnAction = Split(boutons(i)(e), ":")(3)
.BeginGroup = True
End With
Next
Else
With Barre.Controls.Add(msoControlButton, 1, , , True)
.Caption = Split(boutons(i), ":")(0)
.FaceId = Split(boutons(i), ":")(1)
.Enabled = Val(Split(boutons(i), ":")(2))
.OnAction = Split(boutons(i), ":")(3)
If UBound(Split(boutons(i), ":")) > 3 Then .BeginGroup = True
End With
End If
Next
DoEvents
If mode = "usf" Then
GetWindowRect GetActiveWindow, r ' coordonnées rectangle de l'userform
XX = bt.Left * lpppX / 72 'position left du label cliqué en pixel
YY = (bt.Top + bt.Height) * lpppy / 72 ' position top du label cliqué en pixel
YiN = (bt.Parent.Height - bt.Parent.InsideHeight - 3) * lpppy / 72 ' epaisseur de la caption du userform en pixel
'YiN = GetSystemMetrics(15) ' autre methode epaisseur de la caption du userform en pixel mais moins precise
EpS = GetSystemMetrics(5) ' epaisseur des bordures de l' userform en pixel
Barre.ShowPopup r.Left + EpS + XX, r.Top + YiN + EpS + YY ' affichage de la popup au cordonnéees calculées
Else
Barre.ShowPopup
End If
End Function |