Saltar al contenido

BLOQUEAR BOTONES DE MAXIMIZAR Y MINIMIZAR


Recommended Posts

publicado

Que yo sepa el formulario no trae para maximizar ni para minimizar.
En mi visual solo trae la (X)

O a que te refieres con eso?
 

Saludos...

publicado

Hola por lo que entiendo te referis no a un formulario sino a la ventana de Excel.

Agrega este codigo en un modulo. luego llama a la macro correspondiente (OcultarBotonesMinMax / MostrarBotonesMinMax)

 

	Option Explicit
#If VBA7 Then
    #If Win64 Then
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #Else
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #End If
#Else
    Private Declare  Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare  Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Public Sub OcultarBotonesMinMax()
    Application.Visible = False
    SetWindowLong Application.hwnd, GWL_STYLE, GetWindowLong(Application.hwnd, GWL_STYLE) And Not (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX)
    Application.Visible = True
End Sub

Public Sub MostrarBotonesMinMax()
    Application.Visible = False
    SetWindowLong Application.hwnd, GWL_STYLE, GetWindowLong(Application.hwnd, GWL_STYLE) Or (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX)
    Application.Visible = True
End Sub

 

BotonesMinMax.xlsm

publicado
Hace 15 horas, LeandroA dijo:

Hola por lo que entiendo te referis no a un formulario sino a la ventana de Excel.

Agrega este codigo en un modulo. luego llama a la macro correspondiente (OcultarBotonesMinMax / MostrarBotonesMinMax)

 


	Option Explicit
#If VBA7 Then
    #If Win64 Then
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #Else
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #End If
#Else
    Private Declare  Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Declare  Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If

Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const GWL_STYLE As Long = -16

Public Sub OcultarBotonesMinMax()
    Application.Visible = False
    SetWindowLong Application.hwnd, GWL_STYLE, GetWindowLong(Application.hwnd, GWL_STYLE) And Not (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX)
    Application.Visible = True
End Sub

Public Sub MostrarBotonesMinMax()
    Application.Visible = False
    SetWindowLong Application.hwnd, GWL_STYLE, GetWindowLong(Application.hwnd, GWL_STYLE) Or (WS_MAXIMIZEBOX Or WS_MINIMIZEBOX)
    Application.Visible = True
End Sub

 

BotonesMinMax.xlsm

eso es justo lo que queria y funciona muy bien 

solo una cosa mas 

se puede quitar el nombre que sale en la parte superior izquierda 

gracias

publicado

Supongo que te referis a el titulo de la ventana? si es asi puede que esto funcione solo en alguna versiones vieja de excel donde no utilice el Ribbon (2003 y anteriores)

	#If VBA7 Then
	    Private Declare PtrSafe Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String) As Long
	#Else
	    Private Declare  Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
	#End If
	Public Sub WindowText()
	    SetWindowText Application.hwnd, "Hola Mundo"
	End Sub
	

publicado

hola, a todos !

Hace 7 horas, jose susilla dijo:

se puede quitar el nombre que sale en la parte superior izquierda 

lo que aparece en la parte superior izquierda es el nombre del libro (cuando su ventana NO esta maximizada) y no aplica a partir de la version 2013 (SDI)

para cualquier version (hasta ahora) se puede usar la propiedad ".Caption"

  • para excel: application.caption = "nuevo titulo de ventana"
  • para el libro: thisworkbook.windows(1).caption = "nuevo titulo del libro"

application no acepta una cadena vacía (""), es como restablecer el titulo de la aplicación pero acepta un espacio (" ")

saludos,

hector.

publicado

para cambiar el icono esta rutina sirve

	Option Explicit
	#If VBA7 Then
	    Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As LongPtr) As LongPtr
	    Private Declare PtrSafe Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As LongPtr, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As LongPtr
	#Else
	    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
	    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
	#End If
	Private Const WM_SETICON As Long = &H80
	Private Const ICON_BIG As Long = 1
	Private Const ICON_SMALL As Long = 0
	
	Private Const IMAGE_ICON = 1
	Private Const LR_LOADFROMFILE = &H10
	
	Public Sub ChangeIcon(sPath As String)
	    Dim hIcon 'As LongPtr
	    hIcon = LoadImage(0, sPath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
	    SendMessage Application.hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon
	    
	    hIcon = LoadImage(0, sPath, IMAGE_ICON, 32, 32, LR_LOADFROMFILE)
	    SendMessage Application.hwnd, WM_SETICON, ICON_BIG, ByVal hIcon
	End Sub

  • Silvia bloqueó este tema

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

×
×
  • Crear nuevo...

Información importante

Echa un vistazo a nuestra política de cookies para ayudarte a tener una mejor experiencia de navegación. Puedes ajustar aquí la configuración. Pulsa el botón Aceptar, si estás de acuerdo.