Preventing VFP Shutdown During Logoff

Preventing VFP Shutdown During Logoff

Question:
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?

Answer:
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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes