-
[RESOLVED] the v.b form should not be closed even, user pressed close button,how?
Hi!
i developed an application, its fine. now my question is shall i prevent my application not to be closed by the user, that means, if the user clicks the close button of my form, some message has to be displayed, but not closed.
kindly reply me....
-
Re: the v.b form should not be closed even, user pressed close button,how?
Instead of "unload Me" in the click event use something like this:
Code:
Private Sub cmdExit_Click()
MsgBox("I'm not going to let you do that!", vbOK + vbInformation, "Not Allowed")
End Sub
There are other ways but this one is simple. The user would have to use the close button in the upper right of the window or Task Manager. You can also use a close confirmation msg box:
Code:
Dim Response
Response = MsgBox("Close the Program?", vbYesNo + vbQuestion, "Close Confirmation")
If Response = vbYes Then
Unload Me
End
Else
Cancel = 1
End If
-
Re: the v.b form should not be closed even, user pressed close button,how?
I would find an application I can not close to be most annoying.
Why do you want to build this into your app?
Incidentially, if I encountered such an app, I would simply call up Task Manager, terminate the program, and never use it again.
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by Hack
I would find an application I can not close to be most annoying.
Why do you want to build this into your app?
Incidentially, if I encountered such an app, I would simply call up Task Manager, terminate the program, and never use it again.
I agree. It's one thing to have the user confirm they want to exit. Another thing entirely to use an exit button for another purpose.
-
Re: the v.b form should not be closed even, user pressed close button,how?
There is hundreds of reasons why you might not want your app to unload at a certain time. One example would be if it is writing to a disc or usb drive.
Use the QueryUnload event. Something like this in your QueryUnload event of the form:
Code:
Cancel = 1 'cancels the unload, keeps form open
Msgbox "unable to close at this time"
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by Texn
Code:
Dim Response
Response = MsgBox("Close the Program?", vbYesNo + vbQuestion, "Close Confirmation")
If Response = vbYes Then
Unload Me
End
Else
Cancel = 1
End If
Anyone will tell you NEVER USE END. Also Response should not be a variant, it should be declared as a msgboxResult type.
-
Re: the v.b form should not be closed even, user pressed close button,how?
You could just remove the exit button from the screen...maybe (if you only wanted it removed when doing something) you could have it hidden when required then re-show it when the prog's finished doing its stuff :-)
-
Re: the v.b form should not be closed even, user pressed close button,how?
I want to know why the OP wants to make a program that can not be closed by the user.
-
Re: the v.b form should not be closed even, user pressed close button,how?
its not too sinister. Im making programs for use in a factory for work stations were only certain task is performed. you do NOT want a general operative closing the app and rooting through system files out of "curiosity" for example, or trying to edit users db's or just plain messing around.
make sure the form is maximised and remove the "x" button. no way around task manager though, unless the182guy's solution works for that as well?
-
Re: the v.b form should not be closed even, user pressed close button,how?
There's also ways of making it always-on-top, which would be over everything and would block against certain windows based operations :-)
-
Re: the v.b form should not be closed even, user pressed close button,how?
That still won't disable the Start Menu, which opens up the whole computer.
I have code to disable the Start Menu, but it would take an act of god to get me to post it here.
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by Ellis Dee
That still won't disable the Start Menu, which opens up the whole computer.
Maximised and full screen would cover the start menu *EVEN* if the taskbar was set to always on top :-P
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by smUX
Maximised and full screen would cover the start menu *EVEN* if the taskbar was set to always on top :-P
Covered <> Disabled
Pressing Ctrl+Esc or the Start key still brings up the Start Menu in maximized border-less apps, even if they're set to always-on-top.
Always-on-top has a hierarchy, and the Start Menu's always-on-top takes precedence over all others.
-
Re: the v.b form should not be closed even, user pressed close button,how?
Could always edit the keymap and block ctrl-esc from working that way :-)
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by wolf99
its not too sinister.
I want to hear the reason from the OP.
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by the182guy
Anyone will tell you NEVER USE END. Also Response should not be a variant, it should be declared as a msgboxResult type.
How the heck did I miss THAT one!? :blush:
BTW: What is better about msgboxresult over response?
Thanks
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by Texn
BTW: What is better about msgboxresult over response?
You missed the point there... the data type of the Response variable is Variant.
Variants are bad - they waste memory and are slow. If there is any option, you should always declare your variables with an appropriate data type. In this case:
Code:
Dim response as vbMsgboxResult
..or better still, don't bother with a variable at all:
Code:
If MsgBox("Close the Program?", vbYesNo + vbQuestion, "Close Confirmation") = vbYes Then
Unload Me
Else
Cancel = True
End If
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by si_the_geek
You missed the point there... the data type of the Response variable is Variant.
Variants are bad - they waste memory and are slow. If there is any option, you should always declare your variables with an appropriate data type. In this case:
Code:
Dim response as vbMsgboxResult
..or better still, don't bother with a variable at all:
Code:
If MsgBox("Close the Program?", vbYesNo + vbQuestion, "Close Confirmation") = vbYes Then
Unload Me
Else
Cancel = True
End If
Thanks for explaining this. Makes more sense now. Whenever there is more than one way of doing something, I like to know the pros and cons. :thumb: :thumb:
-
Re: the v.b form should not be closed even, user pressed close button,how?
Hi, Thanks for u r reply, it helped me very much
Quote:
Originally Posted by Texn
Instead of "unload Me" in the click event use something like this:
Code:
Private Sub cmdExit_Click()
MsgBox("I'm not going to let you do that!", vbOK + vbInformation, "Not Allowed")
End Sub
There are other ways but this one is simple. The user would have to use the close button in the upper right of the window or Task Manager. You can also use a close confirmation msg box:
Code:
Dim Response
Response = MsgBox("Close the Program?", vbYesNo + vbQuestion, "Close Confirmation")
If Response = vbYes Then
Unload Me
End
Else
Cancel = 1
End If
-
Re: the v.b form should not be closed even, user pressed close button,how?
Hi, Thanks for u r reply, it helped me very much
Quote:
Originally Posted by the182guy
There is hundreds of reasons why you might not want your app to unload at a certain time. One example would be if it is writing to a disc or usb drive.
Use the QueryUnload event. Something like this in your QueryUnload event of the form:
Code:
Cancel = 1 'cancels the unload, keeps form open
Msgbox "unable to close at this time"
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by Ellis Dee
That still won't disable the Start Menu, which opens up the whole computer.
I have code to disable the Start Menu, but it would take an act of god to get me to post it here.
You mean something like this.....
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
'
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, _
ByVal fEnable As Long) As Long
Public Sub EnableStartMenuButton(ByVal bEnable As Boolean)
Dim lHwnd As Long
lHwnd = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString)
lHwnd = FindWindowEx(lHwnd, 0&, "Button", vbNullString)
Call EnableWindow(lHwnd, bEnable)
End Sub
-
Re: the v.b form should not be closed even, user pressed close button,how?
Quote:
Originally Posted by Hack
I want to know why the OP wants to make a program that can not be closed by the user.
Because it's running on MY computer and is accessed via vnc. I don't want anybody doing anything on MY computer except running one specific program.
This question as been answered ennumerable times and the answer is always because the app isn't being run on the user's computer and the computer owner want's to limit what can be run.