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
| '**********************************************************************************************************************
'* CREATEUR :Patricktoulon Alias chamalin1@msn.com *
'* DATE :23/09/2010 *
'* UTILISATION D'UNE SEULE API LE "USER32.DLL" *
'* EXEMPLE DE USERFORM REDIMENTIONNABLE NOUVELLE VERSION *
'* LES CONTROLS SONT REDIMENTIONNES EN MEME TEMPS *
'* AINSI QUE LES FONT SIZE *
'**********************************************************************************************************************
#If Win64 Then
public Declare PtrSafe Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongLong
Public Declare PtrSafe Function ShowWindow Lib "User32" (ByVal hWnd As LongLong, ByVal nCmdShow As LongLong) As LongLong
Public Declare PtrSafe Function SWLg Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As LongLong, ByVal nIndex As LongLong, ByVal dwNewLong As LongLong) As LongLong
#Else
'Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function SWLg Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
#If VBA6 Then
'si on travaille avec office 32 bits
Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Public Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
'Public Declare Function SWLg Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#ElseIf VBA7 Then
'si on travaille avec office 64 bits
public Declare PtrSafe Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Public Declare PtrSafe Function SWLg Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Longptr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Longptr
Public Declare PtrSafe Function ShowWindow Lib "User32" (ByVal hWnd As Longptr, ByVal nCmdShow As Longptr) As Longptr
#End If
Public old_largeur As Long, handle As Long, old_hauteur As Long, newhauteur As Single, newlargeur As Single
Public Ctl As Object
Sub trois_boutons(uf As Object) 'on va ajouter les deux boutons manquants et l'élasticité a l'userform
'*****************************************************************
'*ici on memorise les dimention de depart de l'userform *
old_largeur = uf.InsideWidth: old_hauteur = uf.InsideHeight '*
'*****************************************************************
'***************************************************************************************************************
' ici on determine le handle *
handle = FindWindow(vbNullString, uf.Caption) ' *
' ici on applique les changement (&H84CF0080= les trois bouton et l'elasticité) *
SWLg handle, -16, &H84CF0080 '*
'***************************************************************************************************************
'***********************************************************************************************************************************************************
'on memorise a l'interieur du tag du control ses propriétés ainsi que son son font size '*
For Each ctrl In uf.Controls '*
ctrl.Tag = ctrl.Left & ";" & ctrl.Top & ";" & ctrl.Width & ";" & ctrl.Height '*
If TypeName(ctrl) <> "SpinButton" And TypeName(ctrl) <> "Image" And TypeName(ctrl) <> "ScrollBar" Then ctrl.Tag = ctrl.Tag & ";" & ctrl.Font.Size '*
Next '*
'***********************************************************************************************************************************************************
End Sub
Sub plein_ecran()
' on affiche le userform en plein ecran avec l'api showwindowa de la user32.dll bien moins lourd que mes versions precedente de maximisation de l'userform et plus rapide et plus propre
'1= mode normal:3 =maximiser:6 =minimiser
'le handle du userform a été declaré en public au debut du module et identifié dans la routine des trois boutons il n'est donc plus necessaire de l'identifier
ShowWindow handle, 3
End Sub
Sub maForm_Resize(usf As UserForm)
'ici on determine le multiplicateur qui differenci la dimention de base a celle actuelle de l'userform
newlargeur = usf.InsideWidth / old_largeur: newhauteur = usf.InsideHeight / old_hauteur
'ici on boucle sur tout les controls
For Each Ctl In usf.Controls
ppe = Split(Ctl.Tag, ";") 'on coupe le tag par les ";"
'et on applique le multiplicateur au controls pour la largeur et la hauteur en une seule ligne
Ctl.Move ppe(0) * newlargeur, ppe(1) * newhauteur, ppe(2) * newlargeur, ppe(3) * newhauteur
'l'element(4) de ppe contient le font size du controls
If UBound(ppe) = 4 Then Ctl.Font.Size = ppe(4) * newlargeur
Next
End Sub |
Partager