LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the Close Event for my application if it is generated by Windows and not by the application's panel or menu?

Hi All,
 
I know how to manage the Close event generated by my applications (Panel [X] or Menu).
What I don't know, is how to trap the close event forced by the OS, for example closing the application on the Task Bar (right click+close) or by Task Manager or when Windows is shutting down, etc.
 
Anybody can help me?
Thank you
 
0 Kudos
Message 1 of 8
(5,617 Views)
If you open up the properties window of your main panel in the uir there is an entry under panel settings called Close Control.  Click on it and you can select a control on your panel "such as a quit button" that will receive an Event Commit callback when the OS closes your application. 
If you do not have a visable control that does what you want it to do when the program is terminated, just create a hidden control with a callback that does what you want and tie it to the Close Control property for the panel.
0 Kudos
Message 2 of 8
(5,602 Views)
Hi Laser,

You just need to create a panel callback, then properly handle the EVENT_CLOSE event it receives.  This will be processed by the panel callback regardless of how the panel was actually closed.  To create the panel callback, just specify a callback name in the Edit Panel dialog, then from the Code menu, choose to generate the panel callback (or all callbacks, or all code).

Hope this helps.

Mert A.
National Instruments
0 Kudos
Message 3 of 8
(5,592 Views)
Hi Laser,

Am I not understanding your question?  Please let me know if you are still having problems.

Mert A.
National Instruments
Message 4 of 8
(5,578 Views)

Thank you All, but I'm still having problems.

Here below there is a simple example of what I do to catch the Close Event:

#include <utility.h>
#include <cvirte.h>  
#include <userint.h>
#include "ApplClose.h"

static long int hMain;

int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((hMain = LoadPanel (0, "ApplClose.uir", MAIN)) < 0)
  return -1;
 DisplayPanel (hMain);
 RunUserInterface ();
 DiscardPanel (hMain);
 return 0;
}

int CVICALLBACK MainWnd (int panel, int event, void *callbackData,
  int eventData1, int eventData2)
{
 switch (event)
 {
  case EVENT_CLOSE:
   MessagePopup ("ApplClose", "Close Event trapped!");
   QuitUserInterface (0);
   break;
 }
 return 0;
}

The UIR file has a void panel, where the panel callback is MainWnd().

 

This works if I close the application clicking the [X] on the application title bar or if I type Alt+F4 while my application has the focus.

If I close the application using Task Manager or pressing the right click on it (on the Windows task bar) then selecting Close, the application closes without displaying me the MessagePopup().

 

Merv, how can I access "panel properties" in the UIR file? I'm working with CVI 7.0 and I didn't find the way.

 

Again, thanks.

0 Kudos
Message 5 of 8
(5,567 Views)

Hi,

Try  InstallMainCallback(..)  and  EVENT_END_TASK.  See Labwindows/CVI help for deails.

Message 6 of 8
(5,553 Views)
I appologize for the confusion.  Ovrabek is correct in suggesting the main callback.  You must install a main callback which handles the EVENT_END_TASK event.  See this thread for details.

Happy coding.

Mert A.
National Instruments
0 Kudos
Message 7 of 8
(5,545 Views)

Thank you All,

It does work!

0 Kudos
Message 8 of 8
(5,542 Views)