LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to load and show several panels simultaneously?

I am not familiar with CVI's UI mechanism.
My functions to load,hide,discard panels are exported from Dll, and called
dynamically. How much and when panels will be loaded and showed is uncertain.
Then where or when to put RunUserInterface?
How to make them co-exist peacefully?

Thanks in advance.
0 Kudos
Message 1 of 4
(3,352 Views)
RunUserInterface only once, typically (but not necessarily) after all panels are loaded (using LoadPanelEx if the function will be in a DLL). You can call RunUserInterface from your exe (if it's in CVI) or from the DLL. You can then DisplayPanel() or HidePanel() whenever you want.

If you're creating a DLL, let CVI do the work of setting it up. Set the Target Type to DLL (in the Project window, select Build >> Target Type >> Dynamic Link Library). After you create the UIR file (or at least start it, create a Close Control and assign a callback function name to it) and save it, from the UIR window, select Code >> Generate >> All Code. CVI will create a function InitUIForDLL. In this function will be a commented out call to RunUserInterface. If your calling exe file
doesn't call RunUserInterface, uncomment this call. You must export InitUIForDLL and call it from your exe.

To export any function from a DLL, create a .h file with the prototypes of any function you want to export. I name the .h file ProjectName_Exports.h. The functions will typically be declared as
extern int __cdecl FunctionName(..)
Add the .h file to your project. From the project window, goto Build >> Target Settings >> Exports >> Change, then select the .h file.

Look at the sample program C:\Program Files\National Instruments\MeasurementStudio\CVI\samples\userint\panel.prj. If doesn't use a DLL but it shows LoadPanel, RunUserInterface, DisplayPanel, and HidePanel.
0 Kudos
Message 2 of 4
(3,352 Views)
Thank you for your help, Al S.
Still need your help.:-)
My major problem is in CVI's User Interface.

1) Should I call both DiscardPanel for each panel and
QuitUserInterface when I exit the program? Which one
should be called first?

2) There's a CVICALLBACK for OK button of the panel.
switch (event)
{
case EVENT_COMMIT:
HidePanel(GetActivePanel ());
break;
}
But when I click on OK, sometimes all panels are hidden,
sometimes only the active one.(suppose several panels are
displayed at that time.)

3) When I debug in VC, after RunUserInterface is called
from Dll, the panel pops up, and the debugging seems
terminated there.

I have attached some code snippet.
0 Kudos
Message 3 of 4
(3,352 Views)
1) Normally you QuitUserInterface before you DiscardPanel. If you discard your parent panel, all child panels will be discarded also.

2) If you hide a parent panel, all of its child (and grandchild, etc.) panels will be hidden. I'm guessing when all panels are hidden, the active panel is the parent panel.

3) I don't know if you can debug VC and CVI at the same time. I have previously done one at a time. If you're working on a problem in CVI, try the following steps.
3.1 Compile your VC code into an exe.
3.2 In the CVI project window for your DLL, select Run >> Select External Process, then enter the path to your VC exe in the Program Name box and select OK.
3.3 In any CVI window, select Run >> Debug YourVCProject.exe. You'll now be using the CVI environment to debug your DLL.

Here's some notes about your DisplayAPanel problem.

Your comment and code:

/** When the first DisplayAPanel is called, the Panel pops up,
and the debugging shows the execution of code stops here.
...
*/

void DisplayAPanel(int handle)
{
static int bRunFlag=0;

if (handle >= 0)
{
DisplayPanel(handle);
}

// Make sure RunUserInterface run only once
if (bRunFlag == 0)
{
RunUserInterface();
bRunFlag = 1;
}
}

RunUserInterface returns only when QuitUserInterface is called. So the first time you go into DisplayAPanel, you never set bRunFlag = 1 and return until you call QuitUserInterface. You can call DisplayAPanel again from your VC code, but it never sees bRunFlag == 1.
If you let CVI automatically generate the initial code for your DLL, it would have created a function called InitUIForDLL. Do RunUserInterface here and call InitUIForDLL once from your VC code as part of some init routine. Remember that RunUserInterface (and therefore InitUIForDLL) won't return until QuitUserInterface, so you need to put the VC call to InitUIForDLL where you don't need to continue sequential execution until after QuitUserInterface and where VC will still run other events. Or you need to structure your VC code so the CVI DLL UI takes over and you don't go back to VC until your QuitUserInterface.
0 Kudos
Message 4 of 4
(3,352 Views)