Ver Mensaje Individual
  #9 (permalink)  
Antiguo 26/05/2010, 09:44
Avatar de Pablus00
Pablus00
 
Fecha de Ingreso: diciembre-2003
Ubicación: A un click de distancia
Mensajes: 1.044
Antigüedad: 15 años, 11 meses
Puntos: 11
Bloquear Btn Cerrar (X) de un Form Excel

Hola colegas, luego de mucho buscar encontre un codigo que oculta el boton cerrar (X) de un form, solamente peguen el codigo dentro del formulario:


Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
'API Functions that need to be called to Disable the Close Button on the Form
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private hWnd As Long

Private Sub UserForm_Initialize()
Dim hMenu As Long
Dim menuItemCount As Long
'Get the handle of the User Form
'This is used because there is no property present in the UserForm that gives the HWND
hWnd = FindWindow(vbNullString, Me.Caption)
'Get the Handle of the Menu
hMenu = GetSystemMenu(hWnd, 0)
If hMenu Then
'Get the Number of Items present in the Menu
menuItemCount = GetMenuItemCount(hMenu)
'Remove the system menu Close menu item.
'The menu item is 0-based, so the last
'item on the menu is menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, MF_REMOVE Or MF_BYPOSITION)
'Remove the Separator line from the Menu
Call RemoveMenu(hMenu, menuItemCount - 2, MF_REMOVE Or MF_BYPOSITION)
'Redraw the menu, this will refresh the Title Bar and disable the X button
Call DrawMenuBar(hWnd)
End If
End Sub
__________________
-- Nunca te des por vencido, aún vencido -- Web