Close button does not entirely unload project
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Close button does not entirely unload project

  1. #1
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122

    Close button does not entirely unload project

    I have a project that fails to totally unload the app when the close button is selected ('X' in control box at top of the form). I have to put a button in the form to close the app completely from memory using something like:
    Code:
    Private Sub exitNow()
        Unload Me
    End Sub
    Why will the app not unload with the 'Close' button on the form itself? What can I do to force it to unload all the way?

  2. #2
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Close button does not entirely unload project

    How about using ;

    Code:
    Private Sub exitNow()
        END
    End Sub
    or do you have some code in the Form_Unload Event ?

    Originally posted by rick7423
    I have a project that fails to totally unload the app when the close button is selected ('X' in control box at top of the form). I have to put a button in the form to close the app completely from memory using something like:
    Code:
    Private Sub exitNow()
        Unload Me
    End Sub
    Why will the app not unload with the 'Close' button on the form itself? What can I do to force it to unload all the way?

  3. #3
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122
    I use the ExitNow method whenever I want the app to unload from somewhere. It is a generic call to unload the app, and yes, I also use the 'END' function in conjunction with 'Unload Me'.

    This works fine and the app unloads correctly IF this function is called. What does NOT work is the close button in the control box at the top of the form (the min, max and close buttons). The close ('X') does not entirely unload the app (i.e. it still shows as running in Task Manager).

    I have to disable the control box and force the app to use my internal functions and methods to close the app completly. the problem is, I want to enable the min/max/close features of the control box.

    Does that make any sense?

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    First, avoid "END": it is an abrubtly stop , and ususally it is not needed at all.
    What you need is:
    stop all loops, deactivate all timers, close and set to nothing all referenced objects, unload all forms.

    To stop loops (those where you have a doevents inside, else your app is frozen...) :
    have a global bStop as Boolean; in query_Unload event of forms where loop is (or of your mainform) code
    bStop = true
    'There code also any timer.enabled = false

    In loops after doevents (or in timers, inside the timper_procedure) code:
    Code:
    if bStop then 
    
      'close any private opened object, like word doc, 
      'recordsets and so on that belongss to this procedure
      'if any
      
      exit sub
    end  if
    In main form query unload, ensure you unload all forms:
    Code:
    Dim FrmX as Form
    For Each FrmX in Forms
        If FrmX.hwnd<>Me.hwnd  'no sense to unload this already unloading form
               Unload FrmX
         end if
    Next
    Note the code for cleaning you write in query unload will be
    called also when user press the "X" button...But if you call "end",
    the code in quety unload of any other form will not trig. Nor will
    any code in any other object or in your same object after
    the "end" line.
    Last edited by Cimperiali; July 12th, 2004 at 09:40 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Two thread to read on this subject:

    "Never use End"
    http://www.codeguru.com/forum/showth...ht=end+keyword

    "When even End does not work,
    and instead it is the cause of the matter"
    http://www.codeguru.com/forum/showth...ht=end+keyword
    And in this one look at one of the last answers (sotoasty gave)
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #6
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122

    [Resolved]That's what I was looking for!!!

    This is all good information!!! I was looking for the form_QueryUnload event!

    Thanks for the help. I got it from here!

  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Nice...

    Nice you got it.
    Now, do some more job, and try without "End" command...
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  8. #8
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122
    Done and done...

    I took all of your advise and reqorked the closeApp functionality to ensure that all aspects of the app are removed.

    Thanks for your help. All of you have been tremendously helpful.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center