Results 1 to 22 of 22

Thread: [RESOLVED] the v.b form should not be closed even, user pressed close button,how?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Resolved [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....

  2. #2
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  4. #4
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    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.

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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"
    Chris

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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.
    Chris

  7. #7
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  9. #9
    Hyperactive Member
    Join Date
    Apr 2007
    Location
    cobwebbed to PC
    Posts
    311

    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?

  10. #10
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  11. #11
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    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.

  12. #12
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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
    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.

  13. #13
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    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.

  14. #14
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  16. #16
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    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!?

    BTW: What is better about msgboxresult over response?

    Thanks

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  18. #18
    Lively Member
    Join Date
    Nov 2006
    Location
    Ft. Worth, Texas
    Posts
    67

    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.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    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

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    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"

  21. #21
    New Member
    Join Date
    May 2007
    Posts
    12

    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

  22. #22
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width