LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

shutdown program with the "X"; which library need?

Hallo everybody,

I've included "windows.h", but I cannot close my program by using the "x" from the Win-Panels.

What's wrong?

Florian
0 Kudos
Message 1 of 5
(3,346 Views)
You don't need any special library nor windows.h to shutdown the program with the "X" icon.

You have two choices: either you have a button that already closes the program, in which case you must simply indicate this control in the "Close control" attribute of the panel, or you must create a panel callback and trap the EVENT_CLOSE event to shutdown the program.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 5
(3,336 Views)
Here are a few more details.
A typical CVI program uses RunUserInterface to start the user interaction, then uses QuitUserInterface to end the user interaction and close the open windows.
If you have a Quit button on your panel: In the UI Editor, if you double click on a blank spot on your main panel (to edit the panel), you'll see a Panel Setting for Close Control. Use this if you have a command button you want to use to quit your application. The callback for this button will need to call QuitUserInterface in the case for EVENT_COMMIT. If you select this control as the panel Close Control before running the code generator, the call QuitUserInterface(0); will automatically be included in the callback. If you do it after the fact, you can include QuitUserInterface(0); in the case for EVENT_COMMIT. The X (Close) button on the window will know which callback to use if the control is identified as the Close Control.
Note: the CVI controls menu has a Quit control which saves you a couple of steps. In the UI Editor, right-click on a blank spot on the panel (to get the control menu), then click on Custom Controls, then Quit button. You'll get a control which already has a callback function name assigned to it. If you add this custom control before running the code generator, this control will be assigned as the default Close Control so the code generator will automatically add QuitUserInterface to the callback.
If you don't have a Quit button and only want to use the X button on the window, you need to generate a panel callback. In the UI Editor, double click on a blank spot on your main panel (to edit the panel). Enter a function name (e.g. panelCallback) in the box labeled Callback Function and click OK. In the UI editor, click on Code >> Generate >> Panel Callback. Then click on Code >> View >> Panel Callback. In the case for EVENT_CLOSE, add a call to QuitUserInterface(0);
0 Kudos
Message 3 of 5
(3,325 Views)
I have problems using the little X button as well, I use GetUserEvent and I don't seem to receive any EVENT_CLOSE events.

Why is this? Do I need to use a panel callback? Would that work if I don't use RunUserInterface()?
0 Kudos
Message 4 of 5
(3,226 Views)
You cannot use GetUserEvent to receive EVENT_CLOSE.GetUserEvent only handles EVENT_COMMIT and user events (this is a legacy function that predates RunUserInterface / QuitUserInterface, which are more commonly used functions.
 
You do need to have a callback function to respond to EVENT_CLOSE. You can follow Al's suggestion in his last paragraph, except that  instead of calling QuitUserInterface, you should instead set some global variable that you can then check in your main program's loop, as an exit condition. For this to work, make sure you are passing 0 as the first parameter of GetUserEvent, so that the function call doesn't wait until a commit event happens before returning.
 
Luis
NI
0 Kudos
Message 5 of 5
(3,211 Views)