Close(ok) Button

Discussion in 'Questions (Windows Mobile)' started by TWELVE, Jun 3, 2008.

  1. TWELVE

    TWELVE Active Member Licensed User

    Hello,

    i've got a question regarding the close/ok button every device app does have in the upper right corner.

    My App has two ways to exit out of it.One is through a button and the other one is by use of the menu.I do some cleanup before i really terminate the application.

    This looks like this:


    Code:
    Sub Button3_Click
    ' Quit Button
    ExitApp
    End Sub

    ...

    Sub Menu5_Click
    ' Menu Quit
    ExitApp
    End Sub

    ...


    Sub ExitApp
    ...
    do some clean up
    ...
    AppClose
    End Sub

    If the user pushes the close/ok button, the app just terminates without doing any of my cleanup tasks.
    To have the cleanup also done in this case, i just added the following:

    Code:
    Sub Form1_Close
    ExitApp
    End Sub
    This does not work as i expected.I get some excpetion messages related to file access and some (for me ) unpredictable behavior ( infinite loop for instance).Maybe these exceptions have to do with the form1 closure.


    - can someone explain, why these exceptions occur..? I ran through the code, but i cannot explain this behavior, even then if i take into account that my form is ( probably ) already closed by the OS..?

    -Is there a chance to just catch the close/ok button event without having the OS close the form..?


    cheers

    TWELVE
     
  2. Rioven

    Rioven Active Member Licensed User

    Hi twelve,

    Is it maybe the application was just minimized or just hide in backround when when closing the form?

    ie. when using the formlib.dll library.
    form1.New1("form1",B4PObject(1)) '1st form library to enable minimize button
    form1.MinimizeBox=True 'X' or 'OK' press just hide in background


    make form1.MinimizeBox=false to disable.
     
    Last edited: Jun 3, 2008
  3. Erel

    Erel Administrator Staff Member Licensed User

    AppClose closes the main form and therefore launches Sub Form1_Close which then calls AppClose again.

    The simplest solution is to move your cleanup code into Sub Form1_Close.

    You can use Form.CancelClose to cancel the closing process.
     
  4. TWELVE

    TWELVE Active Member Licensed User

    This was exactly the issue.I didn't know that AppClose calls the Form1_Close Sub.Is that documented somewhere in the manual ? If so i didn't find it.


    How is the syntax then, do you have an example piece of code..?


    The Basic4PPC help is very poor, often i do not understand how a certain instruction or parameter does work, sometimes i don't even understand what the instruction does.


    @Rioven: no i do not use the fullscreen stuff from the formlib, yet.

    kind regards


    TWELVE
     
  5. Rioven

    Rioven Active Member Licensed User

    Hi TWELVE,
    This works for me.

    Code:
    Sub Form1_Close
    If Msgbox("quit application?","",cMsgboxYesNo,cMsgboxQuestion)=cyes Then
    DoSomeCleanUp 
    AppClose
    Else
    form1.CancelClose
    End If
    End Sub
    Not for fullscreen but for the 'x' or 'ok' button on top right of the form to give you an option just to hide in background or to terminate the application. Most applications does use the hiding in background.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Did you follow the link in my previous?
     
  7. TWELVE

    TWELVE Active Member Licensed User

    Erel,

    i'm sorry, did not realize that this was a link..:D

    cheers

    TWELVE
     
  8. cdeane

    cdeane Member

    I have full screen on my ppc App. But I get a double take with Msgbox.
    I have to accepet Yes or No twice to get it to work.

    Code:
    Sub ImageButtonExitForm1_Click
      
    Msgbox ("Do you want to quit?",, cMsgBoxYesNo)
        Form1.Close
     
    End Sub

    Sub Form1_Close
         
    If Msgbox ("Do you want to quit?",, cMsgBoxYesNo) = cNo Then
              Form1.CancelClose
          
         
    End If
    End Sub
     
    Last edited: Jun 6, 2008
  9. cdeane

    cdeane Member

    So I asume there is no way to use this CancelClose in full screen format?
     
  10. Standa

    Standa Member Licensed User

    Hi, try this:
    Code:
    Sub ImageButtonExitForm1_Click
        Form1.Close
    End Sub

    Sub Form1_Close
         
    If Msgbox ("Do you want to quit?",, cMsgBoxYesNo) = cNo Then
              Form1.CancelClose   
         
    End If
    End Sub
     
  11. cdeane

    cdeane Member

    Thanks Standa
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice