|
-
May 23rd, 2007, 01:50 AM
#1
Thread Starter
Addicted Member
[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....
-
May 23rd, 2007, 04:52 AM
#2
Lively Member
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
-
May 23rd, 2007, 05:28 AM
#3
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.
-
May 23rd, 2007, 06:21 AM
#4
Lively Member
Re: the v.b form should not be closed even, user pressed close button,how?
 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.
-
May 23rd, 2007, 07:48 AM
#5
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"
-
May 23rd, 2007, 07:53 AM
#6
Re: the v.b form should not be closed even, user pressed close button,how?
 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.
-
May 23rd, 2007, 07:55 AM
#7
PowerPoster
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
May 23rd, 2007, 08:04 AM
#8
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.
-
May 23rd, 2007, 11:14 AM
#9
Hyperactive Member
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?
-
May 23rd, 2007, 11:17 AM
#10
PowerPoster
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
May 23rd, 2007, 11:22 AM
#11
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.
-
May 23rd, 2007, 11:27 AM
#12
PowerPoster
Re: the v.b form should not be closed even, user pressed close button,how?
 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
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
May 23rd, 2007, 11:53 AM
#13
Re: the v.b form should not be closed even, user pressed close button,how?
 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.
-
May 23rd, 2007, 12:03 PM
#14
PowerPoster
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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
May 23rd, 2007, 12:08 PM
#15
Re: the v.b form should not be closed even, user pressed close button,how?
 Originally Posted by wolf99
its not too sinister.
I want to hear the reason from the OP.
-
May 23rd, 2007, 03:17 PM
#16
Lively Member
Re: the v.b form should not be closed even, user pressed close button,how?
 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!?
BTW: What is better about msgboxresult over response?
Thanks
-
May 23rd, 2007, 03:28 PM
#17
Re: the v.b form should not be closed even, user pressed close button,how?
 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
-
May 23rd, 2007, 08:15 PM
#18
Lively Member
Re: the v.b form should not be closed even, user pressed close button,how?
 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.
-
May 29th, 2007, 04:33 AM
#19
Thread Starter
Addicted Member
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
 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
-
May 29th, 2007, 04:36 AM
#20
Thread Starter
Addicted Member
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
 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"
-
May 29th, 2007, 08:44 AM
#21
New Member
Re: the v.b form should not be closed even, user pressed close button,how?
 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
-
Mar 10th, 2008, 01:14 PM
#22
Lively Member
Re: the v.b form should not be closed even, user pressed close button,how?
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|