Results 1 to 13 of 13

Thread: Prevent a form from being closed

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    18

    Angry

    I want that my form should not be closed by either clicking any control buttons on the form, as well as not be closed by by clicking End task in the task manager list of programs.
    Is there something called Hook function?

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    You can do this by using DeleteMenu to remove the Close item from the system menu.

    It doesn't work for End Task, but then again Windows is the OS, so it can decide what to close, if you know what I mean. I don't think there's a way to mark a program as unclosable from End Task, but heck, I've been wrong before.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'Step 1  
    'disable the close button of a form
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) 
       if unloadmode = vbFormControlMenu then 
           cancel = true  'because you still want to be able to close via code 
      end if 
    End Sub 
    
    'Step 2
    'disable the alt/ctrl/delete functions
    Private Declare Function SystemParametersInfo Lib _
    "user32" Alias "SystemParametersInfoA" (ByVal uAction _
    As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
    ByVal fuWinIni As Long) As Long
    
    Sub DisableCtrlAltDelete(bDisabled As Boolean)
        Dim X As Long
        X = SystemParametersInfo(97, bDisabled, CStr(1), 0)
    End Sub
    
    Private Sub Command1_Click()
       Call DisableCtrlAltDelete(True)
    End Sub
    
    Private Sub Command2_Click()
       Call DisableCtrlAltDelete(False)
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    As far as I am aware you cannot stop the program appearing in the list of processes in task manager, but you can disable the close buttons, and the close option, see the post I made earlier:

    http://forums.vb-world.net/showthrea...threadid=32654
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    crispin:

    If you disable the alt/ctrl/delete you can't see the task manager so it's no matter what is in it.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    can you not right-click on the clock and get it without using ctrl-alt-del?

    In NT you can anyway.

    [Edited by crispin on 09-27-2000 at 09:26 AM]
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  7. #7
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    In your form_QueryUnload routine, you can test for the source of the close. Then you can decide if you want to cancel the close.

    See QueryUnload Event
    or QueryUnload Event Example
    for more info.

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    can you not right-click on the clock and get it without using ctrl-alt-del?

    In NT you can anyway.


    Yes, but I am assuming that if you have a program you don't want closed you are not going to show the icon anywhere. The only way to get at it will be your version of options not the users.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754

    Talking

    exactly
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  10. #10
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    Just hide your app in the close program box. when the user hits alt ctrl del your program will now show...... Go to http://www.planet-source-code.com and do a search on "alt ctrl del" and you should get a list of solutions back

  11. #11
    Guest
    If you don't want your program to appear in the proccess list, do this:
    Code:
    App.TaskVisible = False

  12. #12
    Guest
    That only works for Windows NT

  13. #13
    Guest
    This will work for Windows 95/85/ME

    Code:
    Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
    
    Private Sub Form_Load()
        'Hide from Task List
        RegisterServiceProcess GetCurrentProcessId, 1
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Show in Task list
        RegisterServiceProcess GetCurrentProcessId, 0
    End Sub

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