LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

runuserinterface

Hello,

I have a program, which needs to load options from a file. These options are necessary for displaying the the panel. So I have a main function with the following structure:

int main(int argc, char *argv[], int quit) {
LoadOptions();
hdl= LoadPanel(0, "MainPanel.uir", MAIN_PAN);
// Set some Panel Attributes and so on
DisplayPanel(hdl);
RunUserInterface();
}

The problem is, that in LoadOptions some checks are done and I display some panels needing the users input. But before I call RunUserInterface the panels in LoadOptions do not produce an event, so I do not get a response and the program hangs.

How can I overcome the problem?

Thank you

Michael
0 Kudos
Message 1 of 11
(5,005 Views)
Strange behaviour, this. Your structure is the exact copy of my initialization procedure. My main is as follows:

int main (int argc, char *argv[])
{
// Initialization
...

//-----------------------------------------------------
// Preliminary checks and loading parameters from disk
// CanStart () returns 1 on error
//-----------------------------------------------------
if (CanStart (x)) exit (EXIT_FAILURE);

// Program start completion: loading of main panel

RunUserInterface ();

// Program conclusion

return 0;
}

The function for initial checks has this structure:

int CanStart (int x)
{
int errors = 0;

// Loading a panel for user information during checks
// If some error is found => errors++;

if (errors) {
// Display a message on the panel
// Enable a 'OK' button to quit the program
GetUserEvent (1, &pnl, &ctl);

}
return errors;
}

It works: the program waits for the user to press OK button before exiting.
Hope this helps
Roberto


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?
0 Kudos
Message 2 of 11
(5,000 Views)
Thank you Roberto,

I see the solution. I have to force the software to process the eevnts using GetUserEvent.

With this it works for me too!

Michael
0 Kudos
Message 3 of 11
(4,995 Views)
You don't really need to use GetUserEvent. You can use RunUserInterface in both places.

For example:

int main(int argc, char *argv[], int quit) {

// LoadOptions();
hdl= LoadPanel(0, "MyOptionsPanel.uir", MYOPTIONS_PAN);
// Set some Panel Attributes and so on
DisplayPanel(hdl);
RunUserInterface();

hdl= LoadPanel(0, "MainPanel.uir", MAIN_PAN);
// Set some Panel Attributes and so on
DisplayPanel(hdl);
RunUserInterface();
}

The buttons that close your options panel (like OK, Cancel, etc) would need to call QuitUserInterface from their callback functions. QuitUserInterface just causes RunUserInterface to return, giving control back to your calling function (main(), in this case). Then you can load your main panel, display it, and call RunUserInterface again.

There is nothing special about RunUserInterface that implies you can only call it once in your program.

The GetUserEvent solution will also work, but I generally prefer to use RunUserInterface when I can.

-Jeff
Message 4 of 11
(4,955 Views)
Thank you Jeff for this aspect on using RunUserInterface. So I havenow two solutions for my problem. I will figure out which one is better for my special problem.

Michael
0 Kudos
Message 5 of 11
(4,924 Views)
Good to know. This possibility to use RunUserInterface more than once in a program seems obvious... once someone has focused us on it!


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?
0 Kudos
Message 6 of 11
(4,920 Views)
Yes, but I found in another the thread the notice that you can RunUserInterface only once in a program and must use QuitUserInterface to end this.

In my special case this is not possible, as the panel which is used before the call of RunUserInterface in the main function is also used afterwards, so I expect that I get a conflict. So the first solution with GetUserEvent seems to me more proper in this case.

Michael
0 Kudos
Message 7 of 11
(4,893 Views)
Several times I have seen discussions about calling RunUserInterface more than once in a program, but all of these were concenring concurrent calls of it and possible problems arising in programmin this way.

The particular solution Jeff has pointed us to is to call it at different times in program life: call it the first time, next QuitUserInterface, next call RunUserInterface again. It seems this solution has no problems since at every time only one call is made to RunUserInterface.

One last hint for Michael. Pay attention to a particular aspect of GetUserEvent: it returns on every control'a action that fires a EVENT_COMMIT event. That is, if your panel has more than one control on it, you must either set all controls to Normal state instead of Hot apart those that you decide to look at in this moment, or embed GetUserEvent in a loop and discriminate the control ID returned by the function to decide what to do.


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?
0 Kudos
Message 8 of 11
(4,889 Views)
Thank you for pointing out the events coming from different controls. In my case there is only one button. The panel is an information panel with error informations and so on, when something is going wrong, and it expects that the user quits the panel. Its called when an error occurs during startup (before the first call of RunsUserEvent) and also while the program is executed (after the call of RunUserEvent). So I do not see how apply Jeffs solution in that particular case.

However its an interesting information and I am sure I can use it in other situations.

Michael
0 Kudos
Message 9 of 11
(4,890 Views)
Michael,

Now that I better understand what you are trying to do, I have a few more comments:

1) If all you need to do is display a message with an OK button, you can use the MessagePopup() function. This function displays a modal dialog and will automatically remove the dialog when the user presses OK. By "modal", I mean that the user will not be able to click on any other panels in your application while the dialog is up. Because this function removes the dialog automatically, you do not need to call RunUserInterface or GetUserEvent. This may be perfect for you unless you need other controls on your panel.

2) If you cannot use MessagePopup but still want your panel to be modal, then you can use InstallPopup and RemovePopup instead of DisplayPanel and DiscardPanel.

3) The documentation for QuitUserInterface states the following:

"Note: QuitUserInterface causes the most recent active call to RunUserInteface to return after all currently executing callbacks have exited."

According to this, you should be able to nest calls to RunUserInterface with no problems. This way you could use RunUserInterface even if your main panel is already up and you have already called RunUserInterface in your main() function. The first QuitUserInterface call will simply remove your dialog and leave your main panel running.

I hope this helps.

-Jeff
0 Kudos
Message 10 of 11
(4,873 Views)