locked
Close entire application from MODAL form RRS feed

  • Question

  • Hello Experts,

    I have a Modal login form that has a "cancel" and "Login" Button, I would like to close the entire application when clicking on the cancel button

    here is what i have done so far...

    cancel buttons.click

    thisform.release()

    forms Unload event

    CLEAR EVENTS

    I have tried many other things, but upon research I found that the above should work and it doesnt?

    Tuesday, March 12, 2013 3:52 PM

Answers

  • I did it, it works, Thank you guys for your help

    Cancel buttons Click()

    thisform.hide()
    do CloseMyApp in MAIN.prg

    ***CloseMyApp is a function that closes the application of course located in my MAIN>PRG

    FUNCTION CloseMyApp

    ON ERROR MESSAGEBOX( 'error #' + TRANSFORM( ERROR() ) + ;
       ' "' + MESSAGE() + '"' + CHR(13) + 'Line #' + ;
       TRANSFORM( LINENO() ) + CHR(13) +  MESSAGE(1) )

    CLEAR EVENTS CLOSE DATABASES ALL CLOSE TABLES ON SHUTDOWN QUIT ENDFUNC


    Thanks


    • Edited by mikelvfp Wednesday, March 13, 2013 7:16 PM
    • Proposed as answer by Pavel Celba Wednesday, March 13, 2013 7:27 PM
    • Marked as answer by Youen Zen Tuesday, March 19, 2013 8:28 AM
    Wednesday, March 13, 2013 6:58 PM

All replies

  • What's happening when you click the Cancel button? Have you tried tracing the code in the Debugger?

    Tamar

    Tuesday, March 12, 2013 8:24 PM
    Answerer
  • I found a solution, I am just hoping this is ok

    lcExeName = "vfp9.exe"
    ? IsExeRunning(lcExeName)
    **Close the Exe if it is running
    ? IsExeRunning(lcExeName, .T.)
    RETURN
    FUNCTION IsExeRunning(tcName, tlTerminate)
      LOCAL loLocator, loWMI, loProcesses, loProcess, llIsRunning
      loLocator = CREATEOBJECT('WBEMScripting.SWBEMLocator')
      loWMI = loLocator.ConnectServer()
      loWMI.Security_.ImpersonationLevel = 3  && Impersonate
      loProcesses = loWMI.ExecQuery([SELECT * FROM Win32_Process WHERE Name = '] + tcName + ['])
      llIsRunning = .F.
      IF loProcesses.COUNT > 0
        FOR EACH loProcess IN loProcesses
          llIsRunning = .T.
          IF tlTerminate
            loProcess.TERMINATE(0)
          ENDIF
        ENDFOR
      ENDIF
      RETURN llIsRunning
    ENDFUNC

    Please advise me otherwise, but for now this works
    Tuesday, March 12, 2013 8:25 PM
  • Hi Tamar,

    I didnt find anything, But one thing i did notice, If i remove the "READ EVENTS" line in my main.prg my cancel button works just fine

    Tuesday, March 12, 2013 9:33 PM
  • Well, if that is the case, it seems you have a secondary READ EVENTS somewhere else in your code, so use Code References to find it, you only need it one time in main.prg

    Also: Within the IDE don't expect CLEAR EVENTS to close foxpro. It returns to the line after READ EVENTs, and then you may not have any code after that, which would simply reactivate the command window and then you're in the IDE in development mode again. Isn't that fine enough? If you compile as EXE then there is no IDE window and so you return to windows, exiting your application. It will work.

    You shouldn't terminate a process with the code you have just to close it, any files you have open may or may not be cleaned up and if you have a form or dbf open that can cause damage.

    Bye, Olaf.


    Olaf Doschke (Setmics)


    Wednesday, March 13, 2013 7:52 AM
  • I did it, it works, Thank you guys for your help

    Cancel buttons Click()

    thisform.hide()
    do CloseMyApp in MAIN.prg

    ***CloseMyApp is a function that closes the application of course located in my MAIN>PRG

    FUNCTION CloseMyApp

    ON ERROR MESSAGEBOX( 'error #' + TRANSFORM( ERROR() ) + ;
       ' "' + MESSAGE() + '"' + CHR(13) + 'Line #' + ;
       TRANSFORM( LINENO() ) + CHR(13) +  MESSAGE(1) )

    CLEAR EVENTS CLOSE DATABASES ALL CLOSE TABLES ON SHUTDOWN QUIT ENDFUNC


    Thanks


    • Edited by mikelvfp Wednesday, March 13, 2013 7:16 PM
    • Proposed as answer by Pavel Celba Wednesday, March 13, 2013 7:27 PM
    • Marked as answer by Youen Zen Tuesday, March 19, 2013 8:28 AM
    Wednesday, March 13, 2013 6:58 PM