USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Desabilitar o Botão Fechar
Henrique Ribas
não registrado
ENUNCIADA !
Postada em 14/09/2007 09:42 hs   
Prezados Amigos,
 
Estou desenvolvendo uma aplicação e preciso que o botão fechar de uma Janela seja Desabilitado.
 
Alguém teria uma dica de como eu posso fazer isso.
 
Obrigado e bom final de semana a todos.
 
Abraços.
Henrique Ribas
 
   
Ivo
não registrado
ENUNCIADA !
Postada em 14/09/2007 10:00 hs   
Cara no formm tem uma propriedade chamada ControlBox
só que ele desabilita tanto o fechar quanto o Minimizar e o maximizar agora se quer desabilitar apenas o botão fechar procura na net uma API que faça isso, ja fiz uma vez mas nao recordo
abraço
   
João Carlos jr.
RIBEIRÃO PRETO
SP - BRASIL
Postada em 14/09/2007 13:52 hs            
Henrique para remover somente o X vc coloque essa rotina no load do form principal
 
'Rotina remover o X
Dim hMenu As Long
  hMenu = GetSystemMenu(Me.hWnd, 0)
  If hMenu Then
    lItemCount = GetMenuItemCount(hMenu)
    Call RemoveMenu(hMenu, lItemCount - 1, MF_REMOVE Or _
      MF_BYPOSITION)
    Call RemoveMenu(hMenu, lItemCount - 2, MF_REMOVE Or _
      MF_BYPOSITION)
    Call DrawMenuBar(Me.hWnd)
   
Depois vc coloca essa rotina no option explicit ou em um modulo e não esqueça de colocar a propriedade keypress como true no formulario principal.
 
Declare Function DrawMenuBar Lib "User32" (ByVal hWnd As _
  Long) As Long
Declare Function GetMenuItemCount Lib "User32" (ByVal hMenu _
  As Long) As Long
Declare Function GetSystemMenu Lib "User32" (ByVal hWnd As _
  Long, ByVal bRevert As Long) As Long
Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Long, _
  ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Const MF_BYPOSITION = &H400
Flw.
 
T+
 

João Carlos Junior

Administrador de Redes - Windows 2003 Srv, Linux

    Desenvolvedor Visual Basic 6.0 com Access, SQL Server, VB .Net e Crystal Reports X

Iniciante em C# e ASP .NET

     
wender
não registrado
Postada em 09/11/2007 11:01 hs   
esse comando faz vc desabilitar o botão x
      Option Explicit

      'Menu item constants.
      Private Const SC_CLOSE       As Long = &HF060&

      'SetMenuItemInfo fMask constants.
      Private Const MIIM_STATE     As Long = &H1&
      Private Const MIIM_ID        As Long = &H2&

      'SetMenuItemInfo fState constants.
      Private Const MFS_GRAYED     As Long = &H3&
      Private Const MFS_CHECKED    As Long = &H8&

      'SendMessage constants.
      Private Const WM_NCACTIVATE  As Long = &H86

      'User-defined Types.
      Private Type MENUITEMINFO
          cbSize        As Long
          fMask         As Long
          fType         As Long
          fState        As Long
          wID           As Long
          hSubMenu      As Long
          hbmpChecked   As Long
          hbmpUnchecked As Long
          dwItemData    As Long
          dwTypeData    As String
          cch           As Long
      End Type

      'Declarations.
      Private Declare Function GetSystemMenu Lib "user32" ( _
          ByVal hwnd As Long, ByVal bRevert As Long) As Long

      Private Declare Function GetMenuItemInfo Lib "user32" Alias _
          "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
          ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long

      Private Declare Function SetMenuItemInfo Lib "user32" Alias _
          "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
          ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long

      Private Declare Function SendMessage Lib "user32" Alias _
          "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, lParam As Any) As Long

      'Application-specific constants and variables.
      Private Const xSC_CLOSE  As Long = -10
      Private Const SwapID     As Long = 1
      Private Const ResetID    As Long = 2

      Private hMenu  As Long
      Private MII    As MENUITEMINFO

      Private Sub Command1_Click()
          Dim Ret As Long

          Ret = SetId(SwapID)
          If Ret <> 0 Then

              If MII.fState = (MII.fState Or MFS_GRAYED) Then
                  MII.fState = MII.fState - MFS_GRAYED
              Else
                  MII.fState = (MII.fState Or MFS_GRAYED)
              End If

              MII.fMask = MIIM_STATE
              Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)
              If Ret = 0 Then
                  Ret = SetId(ResetID)
              End If

              Ret = SendMessage(Me.hwnd, WM_NCACTIVATE, True, 0)
              SetButtons
          End If
      End Sub

      Private Sub Command2_Click()
          Dim Ret As Long

          If MII.fState = (MII.fState Or MFS_CHECKED) Then
              MII.fState = MII.fState - MFS_CHECKED
          Else
              MII.fState = (MII.fState Or MFS_CHECKED)
          End If

          MII.fMask = MIIM_STATE
          Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)
          SetButtons
      End Sub

      Private Sub Command3_Click()
          Unload Me
      End Sub

      Private Function SetId(Action As Long) As Long
          Dim MenuID As Long
          Dim Ret As Long

          MenuID = MII.wID
          If MII.fState = (MII.fState Or MFS_GRAYED) Then
              If Action = SwapID Then
                  MII.wID = SC_CLOSE
              Else
                  MII.wID = xSC_CLOSE
              End If
          Else
              If Action = SwapID Then
                  MII.wID = xSC_CLOSE
              Else
                  MII.wID = SC_CLOSE
              End If
          End If

          MII.fMask = MIIM_ID
          Ret = SetMenuItemInfo(hMenu, MenuID, False, MII)
          If Ret = 0 Then
              MII.wID = MenuID
          End If
          SetId = Ret
      End Function

      Private Sub SetButtons()
          If MII.fState = (MII.fState Or MFS_GRAYED) Then
              Command1.Caption = "Enable"
          Else
              Command1.Caption = "Disable"
          End If
          If MII.fState = (MII.fState Or MFS_CHECKED) Then
              Command2.Caption = "Uncheck"
          Else
              Command2.Caption = "Check"
          End If
      End Sub

      Private Sub Form_Load()
          Dim Ret As Long

          hMenu = GetSystemMenu(Me.hwnd, 0)
          MII.cbSize = Len(MII)
          MII.dwTypeData = String(80, 0)
          MII.cch = Len(MII.dwTypeData)
          MII.fMask = MIIM_STATE
          MII.wID = SC_CLOSE
          Ret = GetMenuItemInfo(hMenu, MII.wID, False, MII)
          SetButtons
          Command3.Caption = "Exit"
      End Sub

     
LCRamos
Pontos: 2843
GOIANIA
GO - BRASIL
Postada em 09/11/2007 17:51 hs            
Coloque no Options Explicit
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal Hwnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
No Formulário:
Private Sub RemoveMenus()
 Dim hMenu As Long
 hMenu = GetSystemMenu(Hwnd, False)  ' True Habilita
 DeleteMenu hMenu, 6, MF_BYPOSITION
End Sub
 
Depois no Formulário que quiser desabilitar chame assim:
 
RemoveMenus
 
vlu//
     
Anderson
não registrado
Postada em 02/02/2016 15:32 hs   
LCRamos, maravilhoso esse código, funcionou perfeitamente.
     
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página