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

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  Desabilitar o "X" do Form sem desabilitar o "_"
ghost_jlp
Pontos: 2843 Pontos: 2843 Pontos: 2843 Pontos: 2843
SÃO PAULO
SP - BRASIL
Postada em 12/01/2007 00:32 hs            
Cole num módulo:
 
Public Const MF_BYPOSITION = &H400
Public Const MF_REMOVE = &H1000
 
Public Declare Function DrawMenuBar Lib "user32" _
(ByVal hWnd As Long) As Long
 
Public Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
 
Public Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, _
    ByVal bRevert As Long) As Long
 
Public Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, _
    ByVal nPosition As Long, _
    ByVal wFlags As Long) As Long
 
Public Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" _
    (ByVal lpClassName As String, _
   ByVal lpWindowName As String) As Long
 
Public vhWnd As Long
Public hMenu As Long
-------------------------------------------------------------------------
 
Cole no evento initialize do form:
 
'Obtain the window handle to the userform
  vhWnd = FindWindow(vbNullString, Me.Caption)
 
  'Obtain the handle to the form's system menu
  hMenu = GetSystemMenu(vhWnd, 0)
 
  If hMenu Then
 
    'Obtain the number of items in the menu
    menuItemCount = GetMenuItemCount(hMenu)
 
    'Remove the system menu Close menu item.
    'The menu item is 0-based, so the Max
    'item on the menu is menuItemCount - 1
    Call RemoveMenu(hMenu, menuItemCount - 1, _
        MF_REMOVE Or MF_BYPOSITION)
 
    'Remove the system menu separator line
    Call RemoveMenu(hMenu, menuItemCount - 2, _
        MF_REMOVE Or MF_BYPOSITION)
 
    'Force a redraw of the menu. This
    'refreshes the titlebar, dimming the X
    Call DrawMenuBar(vhWnd)
 
  End If
 
 
at+ :)
     
LCRamos
Pontos: 2843
GOIANIA
GO - BRASIL
Postada em 13/01/2007 04:17 hs            
Segue ai, uso sem problemas
Coloque no Formulário:
 
Option 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&
-----------------------------------------------------
Private Sub RemoveMenus()
 Dim hMenu As Long
 hMenu = GetSystemMenu(Hwnd, False)
 DeleteMenu hMenu, 6, MF_BYPOSITION
End Sub
-------------------------------------------
No evento que quiser, eu uso no Form_Load
 
Private Sub Form_Load()
 RemoveMenu
 
End Sub
 
 
vlu//
     
Alfterra
Pontos: 2843 Pontos: 2843
SÃO PAULO
SP - BRASIL
Postada em 13/01/2007 11:25 hs            
de todas as formas citadas esta aqui "EU" acho a melhor, num modulo copie:

'A API abaixo trava todas as opções de um form
'ou só as que você desejar que ele trave
'OBS: esta API também é válida para forms MDI
Public Enum OpcoesForm
    Maximizar = 1
    Tamanho = 2
    Mover = 3
    Minimizar = 4
    Restaurar = 5
    Fechar = 6
End Enum
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1
 
Private Const SC_MAXIMIZE = &HF030
Private Const SC_MINIMIZE = &HF020
Private Const SC_MOVE = &HF010
Private Const SC_RESTORE = &HF120
Private Const SC_SIZE = &HF000
Private Const SC_CLOSE = &HF060
Private Const MF_BYCOMMAND = 0
 
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
'Para travar as opções use esta função
Public Sub TravarOpcoes(Opcao As OpcoesForm, gForm As Form)
    Dim hMenu As Long
    hMenu = GetSystemMenu(gForm.hwnd, 0)
    Select Case Opcao
        Case 1
            Call DeleteMenu(hMenu, SC_MAXIMIZE, MF_BYCOMMAND) 'trava o Maximixar
        Case 2
            Call DeleteMenu(hMenu, SC_SIZE, MF_BYCOMMAND) 'trava o tamanho
        Case 3
            Call DeleteMenu(hMenu, SC_MOVE, MF_BYCOMMAND) 'trava o mover
        Case 4
            Call DeleteMenu(hMenu, SC_MINIMIZE, MF_BYCOMMAND) 'trava o minimizar
        Case 5
            Call DeleteMenu(hMenu, SC_RESTORE, MF_BYCOMMAND) 'trava o restaurar
        Case 6
            Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND) 'trava o fechar ( X )
     End Select
End Sub
'por: Alfterra
Public Sub HabilitarX(F As Form)
   Dim hSysMenu As Long
   hSysMenu = GetSystemMenu(F.hwnd, True) 
End Sub
'chamar
'''Call HabilitarX(nomeForm)
'===========================================================
' para desabilitar as opções do form faça o seguinte
'Private Sub Form_Load()
Call TravarOpcoes(Fechar, Me)
Call TravarOpcoes(Maximizar, Me)
Call TravarOpcoes(Minimizar, Me)
Call TravarOpcoes(Mover, Me)
Call TravarOpcoes(Restaurar, Me)
Call TravarOpcoes(Tamanho, Me)
End Sub
alfterra o TED...kkkkkkkkkkkkkk
     
geronimo
não registrado
Postada em 13/01/2007 13:41 hs   
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&
Private Sub RemoveMenus()
Dim hMenu As Long
hMenu = GetSystemMenu(hWnd, False)
DeleteMenu hMenu, 6, MF_BYPOSITION
End Sub
No FORM LOAD:
RemoveMenus
 
     
Zoltran
SÃO PAULO
SP - BRASIL
Postada em 22/01/2007 12:09 hs            
Valeu san, funcionou como queria, obrigado.
     
Zoltran
SÃO PAULO
SP - BRASIL
Postada em 22/01/2007 12:12 hs            
Obrigado o todos pelas dicas, vou guardar todas e usá-las em outra ocasião.
     
Página(s): 2/2     « ANTERIOR  

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