Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable/Disable Close Button

Status
Not open for further replies.

victoryhighway2

Programmer
Jul 18, 2005
42
US
Hello Group,
I found this code on another board to disable the "X" close button on a form in VB6. What I would like to know is, once the Close buttons is disabled in this manner, how can I re-enable it? The reason why I am asking is because I am working on a download window where I don't want the user to use the close button while downloading, but I want to re-enable it when the download is finished. Any suggestions?

Regards,
Geoffrey

Code:
Module:
Option Explicit

Public Const SC_CLOSE = &HF060
Public Const MF_BYCOMMAND = &H0
Public Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function DeleteMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Code:
Form:
Public Sub DisableXbutton(ByVal frmHwnd As Long)
Dim hMenu As Long
hMenu = GetSystemMenu(frmHwnd, 0&)
If hMenu Then
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
DrawMenuBar (frmHwnd)
End If
End Sub
 
What about allowing user to close App if not downloading, but not allowing if you have some downoad going - by detecting users intentions.....?

Code:
Option Explicit
Dim blnDownloadIsOn As Boolean

Private Sub Form_Load()
blnDownloadIsOn = True
End Sub

Private Sub Form_QueryUnload( _
    Cancel As Integer, UnloadMode As Integer)

If blnDownloadIsOn Then
    Call MsgBox("I am sorry, you can not " _
        & " close my App this way now.", _
        vbInformation, _
        "Can Not Close This Way.")
    Cancel = 1
Else
    Call MsgBox("See you later...", _
        vbInformation, "Bye Bye.")
    Cancel = 0
End If

End Sub

To change to other behavior, change Form_Load()
blnDownloadIsOn to False

Would that work for you?

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top