Preventing VFP Shutdown During Logoff

I have a Visual FoxPro 5.0 application that I installed to run as a service on an NT server. Everything works fine except for when the user attempts to log off. During logoff, the VFP/service wants to shut down and fails with the message “Cannot quit FoxPro.”

How can I prevent VFP from reacting to the shutdown message being sent from the NT OS?

Visual FoxPro has a command called ON SHUTDOWN [ShutDownProgram/Method], which allows the developer to trap when an application is closed (either at shutdown, or when the close box on the application window is clicked). When the application is closed, the program/method specified (ShutDownProgram/Method) is called. To prevent the “cannot close VFP” message, you need to create a program that handles what you want to occur when the application is shutdown, and point VFP at it, using the ON SHUTDOWN command.

For example, here is a program that tells VFP to call a program named “ShutDownMyApplication” when the application is closed. ShutDownMyApplication() pops up a messagebox, asking whether you want to close the application. If the user chooses Yes, the application is closed; otherwise the application remains open. To test this code, create a program called TestShut and put the following code into it. Then execute the following command in the command window: DO TestShut.

 *-- TestShut.prg*-- MESSAGEBOX() constants#DEFINE MB_YESNO 4 && Yes and No buttons#DEFINE MB_ICONQUESTION 32 && Warning query#DEFINE MB_DEFBUTTON2 256  && 2nd button default#DEFINE IDYES 6 && Yes button pressed*-- Set things so that ShutDownMyApplication*-- is called when the application is closedON SHUTDOWN Do ShutDownMyApplication*-- Close the application - this will cause*-- ShutDownMyApplication to fireQUITPROC ShutDownMyApplicationlnAnswer = MESSAGEBOX("Close Application", ;               MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2)IF lnAnswer = IDYES    *-- this next line is necessary to     *-- prevent ShutDownMyApplication from     *-- firing again because the QUIT command     *-- is the equivalent of closing     *-- the application    ON SHUTDOWN      *-- this would be a good place to     *-- perform a CLEAR ALL    QUITENDIFENDPROC

Please notice how ON SHUTDOWN is turned off before calling QUIT. If you do not do this, you will not be able to close your application (short of ending the task from the NT task manager).

The call to ON SHUTDOWN should be in the main program of your application.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS