Hello everyone,
I would like to have an UserForm that can be reduced or increased as desired. So I searched on the net and I found a code to display these buttons, which works perfectly.
But, first complication, I already had a code that allowed me to delete the cross, because I want to force the user to click o a button to close the UF, and therefore this code hides me these buttons to reduce and increase UF. So I have to comment this code to be able to have the buttons that are displayed, but then the cross is present.
So I would like to hide or delete this button "cross", but I admit that it is a more complex code than usual and I do not know how to modify it to achieve my purposes.
I would also like, if possible, to hide or delete the button that displays in the UF in full screen.
Here are my codes:
Module to remove the cross:
Private Const mcGWL_STYLE = (-16)
Private Const mcWS_SYSMENU = &H80000
'Windows API calls to handle windows
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#If Win64 Then
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Public Sub RemoveCloseButton(objForm As Object)
Dim lngStyle As LongPtr
Dim lngHWnd As LongPtr
Dim lpClassName As String
lpClassName = vbNullString
If Val(Application.Version) >= 9 Then
lpClassName = "ThunderDFrame"
Else
lpClassName = "ThunderXFrame"
End If
lngHWnd = FindWindow(lpClassName, objForm.Caption)
lngStyle = GetWindowLongPtr(lngHWnd, mcGWL_STYLE)
If lngStyle And mcWS_SYSMENU > 0 Then
SetWindowLongPtr lngHWnd, mcGWL_STYLE, (lngStyle And Not mcWS_SYSMENU)
End If
End Sub
Module to add buttons:
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private hwnd, IStyle
Public Sub AjoutBtn(F As Object)
hwnd = FindWindow(vbNullString, F.Caption)
IStyle = GetWindowLong(hwnd, GWL_STYLE) Or &H70000
SetWindowLong hwnd, GWL_STYLE, IStyle
End Sub
In the Initialize of the UF:
AjoutBtn Me
RemoveCloseButton Me
Many thanks in advance to those who will try to help me! 
PS : Sorry if I made English's mistakes, I'm not English !
Bookmarks