This document contains code to programmatically add minimize and maximize buttons to a userform in VBA. It uses API calls like FindWindow, GetWindowLong, and SetWindowLong to get the window handle, current style, and set a new style respectively. Conditionals are used to handle 32-bit versus 64-bit systems and different window classes depending on the version of Office.
This document contains code to programmatically add minimize and maximize buttons to a userform in VBA. It uses API calls like FindWindow, GetWindowLong, and SetWindowLong to get the window handle, current style, and set a new style respectively. Conditionals are used to handle 32-bit versus 64-bit systems and different window classes depending on the version of Office.
Original Title
PARA COLOCAR ICONOS DE VENTANA DE WINDOWS ,MINIMIZAR
This document contains code to programmatically add minimize and maximize buttons to a userform in VBA. It uses API calls like FindWindow, GetWindowLong, and SetWindowLong to get the window handle, current style, and set a new style respectively. Conditionals are used to handle 32-bit versus 64-bit systems and different window classes depending on the version of Office.
This document contains code to programmatically add minimize and maximize buttons to a userform in VBA. It uses API calls like FindWindow, GetWindowLong, and SetWindowLong to get the window handle, current style, and set a new style respectively. Conditionals are used to handle 32-bit versus 64-bit systems and different window classes depending on the version of Office.
Download as TXT, PDF, TXT or read online from Scribd
Download as txt, pdf, or txt
You are on page 1of 2
Option Explicit
#If VBA7 And Win64 Then
Private Declare PtrSafe Function FindWindow Lib "USER32" _ Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr #Else Private Declare Function FindWindow Lib "USER32" _ Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long #End If
#If VBA7 And Win64 Then
Private Declare PtrSafe Function DrawMenuBar Lib "USER32" (ByVal hwnd As Long) As LongPtr #Else Private Declare Function DrawMenuBar Lib "USER32" (ByVal hwnd As Long) As Long #End If
#If VBA7 And Win64 Then
#If VBA7 Then #If Win64 Then 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 Function SetWindowLongPtr Lib "USER32" Alias "SetWindowLongA" _ (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #End If #Else Private Declare Function SetWindowLongPtr Lib "USER32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long #End If #Else Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long #End If
#If VBA7 And Win64 Then
#If VBA7 Then #If Win64 Then Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" _ Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr #Else Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" _ Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr #End If #Else Private Declare Function GetWindowLongPtr Lib "USER32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long #End If #Else Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long #End If
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000 Private Const GWL_STYLE As Long = (-16)
'AL INICIAR EL FORMULARIO
Private Sub UserForm_Initialize() Dim Windows64 As Boolean ' 'Validamos la versión de Office #If VBA7 And Win64 Then Dim lngMyHandle As LongPtr, lngCurrentStyle As LongPtr, lngNewStyle As LongPtr #Else Dim lngMyHandle As Long, lngCurrentStyle As Long, lngNewStyle As Long #End If ' If Application.Version < 9 Then lngMyHandle = FindWindow("THUNDERXFRAME", Me.Caption) Else lngMyHandle = FindWindow("THUNDERDFRAME", Me.Caption) End If ' #If VBA7 And Win64 Then lngCurrentStyle = GetWindowLongPtr(lngMyHandle, GWL_STYLE) lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX SetWindowLongPtr lngMyHandle, GWL_STYLE, lngNewStyle ' #Else lngCurrentStyle = GetWindowLong(lngMyHandle, GWL_STYLE) lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX SetWindowLong lngMyHandle, GWL_STYLE, lngNewStyle #End If ' #If Win64 Then Windows64 = True #Else Windows64 = False #End If ' End Sub