'*****************************************************************************************************
' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _.
' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| //
' //___// //__\ // //__// // // //__// // // // // // // // // // | //
' // // \\ // // \\ // // // \\ // // // // // // // // // | //
'// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |//
'****************************************************************************************************
' Module RESIZER userform version basic
'version avec api en macro 4
'release 2020 for XLD
'****************************************************************************************************
Option Explicit
Dim OldW#, OldH#
Sub trois_boutons() 'ajoute les 3 boutons et le resize dynamique à l'userform
Dim hwnd&
hwnd = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'api GetActiveWindow
ExecuteExcel4Macro ("CALL(""user32"",""SetWindowLongA"",""JJJJJ""," & hwnd & ", " & -16 & ", " & &H94CF0080 & ")") 'api SetWindowLongA
End Sub
Sub UsfFullScreen() 'met le userform en plein ecran
Dim hwnd&
hwnd = ExecuteExcel4Macro("CALL(""user32"",""GetActiveWindow"",""JCC"")") 'api GetActiveWindow
ExecuteExcel4Macro ("CALL(""user32"",""ShowWindow"",""JJJ""," & hwnd & ", 3)") 'api SetWindowLongA
End Sub
Sub memoControlSize(usf) 'on memorise dans le tag des controls leur position et dimension
Dim CtrL
OldW = usf.Width
OldH = usf.Height
For Each CtrL In usf.Controls
CtrL.Tag = CtrL.Left & ";" & CtrL.Top & ";" & CtrL.Width & ";" & CtrL.Height
On Error Resume Next
CtrL.Tag = CtrL.Tag & ";" & CtrL.Font.Size
CtrL.Tag = CtrL.Tag & ";"
Err.Clear: On Error GoTo 0
If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then
CtrL.Tag = CtrL.Tag & ";" & Replace(CtrL.ColumnWidths, ";", "|")
End If
CtrL.Tag = CtrL.Tag & ";"
Next
End Sub
Sub resiZer(usf)
Dim newW#, NewH#, t, cw$, tc, CtrL, i&
newW = usf.Width / OldW
NewH = usf.Height / OldH
For Each CtrL In usf.Controls
t = Split(CtrL.Tag, ";")
CtrL.Move t(0) * newW, t(1) * NewH, t(2) * newW, t(3) * NewH
If TypeName(CtrL) = "ListBox" Or TypeOf CtrL Is ListBox Then
If CtrL.ColumnWidths = "" Then cw = Application.Rept("80", CtrL.ColumnCount) Else cw = CtrL.ColumnWidths
tc = Split(t(6), "|")
For i = 0 To UBound(tc): tc(i) = Val(tc(i)) * Application.Min(newW, NewH): Next
CtrL.ColumnWidths = Join(tc, ";")
End If
On Error Resume Next
CtrL.Font.Size = t(4) * Application.Min(newW, NewH)
Err.Clear: On Error GoTo 0
Next
End Sub