LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

End task from task bar

Hy there,
I write a data acquisition application which writes data to a file. After
stopping the data acquisition, the file needs to be "closed", some
statistical data needs to be written in the header.
The application has and needs a task bar button. With right click on it, the
user can Close the application.
Is there any function or callback, which is called, before actually closing
my app?
A function call after the RunUserInterface() in the main() function is not
reached.
Or is there a way to prevent the user from closing the app by using the task
bar? (Same thing with ending the process over the task manager...)
Regards

Harald

mailto:HIlg@gmx.net
0 Kudos
Message 1 of 7
(3,979 Views)
If you attach a callback function to your panel within your application is, you can prevent the user by adding a ConfirmPopup()
with your Warning message in the case
EVENT_CLOSE in the callback function of your
panel.
0 Kudos
Message 2 of 7
(3,979 Views)
Hy Arno, Hy NG,
thanks for your reply.

> If you attach a callback function to your panel within your

That's what I tried, but it doesn't have the effect, I wanted.
I attached a sample project to demonstrate, what I mean.

If you run the project, every panel callback can be inserted in a list box.
If the panel callback with event EVENT_CLOSE is called, a message box is
displayed. If the RunUserInterface() in the winMain function returns,
another message box is displayed.
If I close the app with the cross in the upper right corner, both message
boxes appear, if I close it with the close button on the panel, only the
second message box appears, if I close it with right click on the task bar
or with the aid of the task manager, no message box is called.

And this i
s my point: Where do I have to write a function, which is called,
when the user closes the application with one of the latter two methods?

Thanks a lot!
Harald

mailto:HIlg@gmx.net

P.S. Sorry, that my sender address was set to "National Instruments", was by
mistake...



[Attachment CloseProj.zip, see below]
0 Kudos
Message 3 of 7
(3,979 Views)
Closing from the Task Bar is not like closing a panel. It is sending a Windows message to destroy the process. Say for example, you have 5 panels. Each time you pressed the X at the top right, you would just be closing that window. To handle Windows messages destroying the process, you need to install a main callback (callback for the process). There is an EVENT_END_TASK that handles the WM_DESTROY event to the application. Below is a basic example.

int CVICALLBACK MainCB (int panelOrMenuBarHandle,
int controlOrMenuItemID,
int event, void *callbackData, int eventData1,
int eventData2);

int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
re
turn -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "close.uir", PANEL)) < 0)
return -1;

InstallMainCallback (MainCB, 0, 1);
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}

int CVICALLBACK MainCB (int panelOrMenuBarHandle,
int controlOrMenuItemID,
int event, void *callbackData, int eventData1,
int eventData2)
{
switch (event)
{
case EVENT_END_TASK:
MessagePopup ("Test", "Test");
break;
}
return 0;
}

Best Regards,

Chris Matthews
Measurement Studio Support Manager
0 Kudos
Message 5 of 7
(3,979 Views)
Harald:

Yes, LabWindows/CVI provides a mechanism for responding to closes from the Task Manager or the Task Bar. National Instruments has an excellent knowledge base article that describes how to do this. You can reach this article at

http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/71c7a90a28f324298625666d00534bac?OpenDocument

Good Luck,

Chris Wood
Applications Engineer
National Instruments
0 Kudos
Message 4 of 7
(3,979 Views)
Hy Chris,

> excellent knowledge base article that describes how to do this. You

Excellent is the right word! Exact the information I was looking for.
I was searching the knowledge base, but didn't find anything about this
subject...

Thanx a lot

Harald

mailto:HIlg@gmx.net
0 Kudos
Message 6 of 7
(3,979 Views)

Good App. Note and example by Chris Mathews.  Apparently Windows 7 will also result in an EVENT_CLOSE for the main panel, in addition to the EVENT_END_TASK in the MainCallback.  This is extremely inconvenient when attempting to swallow the task bar generated closure (as in C.M.'s' example).

0 Kudos
Message 7 of 7
(3,203 Views)