LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Working with multiple Panels

Greetings everyone,

I'm a bit of a beginner with CVI. When it came to poudning out quick programs with GUIs I normally reach for VB (yeah I know but it's quick and dirty). My current research office lead doesn't know VB and asked me to write my prgrams in CVI. Good ole C code....or so i thought.

In VB I could create, call, and hide multiple windows (panels in CVI). Each window had it's own code file that would be added to the project. I've been digging through the forum, and I hear this is possible in CVI but I don't understand some things.

1. You can't use main{} more than once, so what do you use in the code for the subsequent panel .c files?

2. I've read that one should only call the show panel function once, so how do you show/hide panels (i.e. if I place a button on panel A how do I make that button hide panel A and open the panel B)?

I can write all the code in one .c file but that makes for messy code. Any help would be a big help to me....and eventually my office lead.
0 Kudos
Message 1 of 6
(4,938 Views)

In CVI you can have multiple panels and have some of them opened at the same time and others that are opened and closed upon some condition (signals coming from outside or user interaction or whatever you can think of). Differently from VB you don't have that rigid association one-panel-one-file: you can store multiple panels into a single UIR file and manage all of them in one source file only or divide your code into several .UIR and .C files according to your needs / desires / habits.

So how do you handle all of this? Normally one panel (let's call it the main panel) is loaded inside the main { } function and displayed immediately before RunUserInterface ( ) function, which starts event handling.

Supposing on the main panel ther's a button to load a new panel, in the button callback you will call LoadPanel and DisplayPanel and that's all: the events related to controls on that panel will be automatically handled by the system in the correct way. In the same way, when a panel is no longer needed you can hide it with HidePanel (in that case you can reshow it simply with a new DisplayPanel) or discard it from memory with DiscardPanel (in which case you will need to reload it before using it again).

Each panel is identified by a panel handle, which permits to address it and all objects that are on it. This permits to load more than one instance of the same panel as separate and independent entities. Or to have the same callback associated to controls on different panels, so to reuse the code when needed.



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 6
(4,933 Views)
Roberto,

Thanks for the quick response.

So, let's say that I'm starting my program off with a "welcome" panel. As you've said, this is the first panel loaded inside main{}. Now the welcome panel has an "Open" button (which already has the file open dialog stuff working) and an "Exit" button.

After the user selects the file they wish to open I want another panel to pop-up and allow them to work with the data inside the file they selected. from what you're saying I can either have the pop-up panel created inside the same .UIR as the "Welcome" panel or I can create separate .UIRs....neat. That would mean that inside the c-code for the open button I would need to tell the "Welcome" panel to HidePanel() and the pop-up panel to DisplayPanel(). That makes sense, and not too different from what I'm used to.

Now, if I want to keep the code files separate how do I write the .C code for the pop-up panel. Either way I need the #include mypanel.uir (whether theyre in the same .UIR or separate), but how do I get around the dual main{} problem? Is there something that I put into the pop-up panel .C code that takes the place of the main{}?
0 Kudos
Message 3 of 6
(4,923 Views)
Gwain,
 
There is no need for another main{} because you can just put all the callbacks (for each event that is generated by your second panel) in a second file.  Include that .c file in the project and you are set.  The RunUserInterface(); function oin the lone main() is the event handler and will call the appropriate callbacks as events are generated.
 
(You may need to brush up on the static and extern keywords to manage the scope of any variables such as panel handles that should not / should be global. Here is one thread that might be useful)
 
By the way you will need to "#include mypanel.h" in your course code rather than mypanel.uir.
 
I highly recommend you try out the examples that ship with CVI. Under Help there is a Find Examples option. Search for "panels" and look at the examples - I think it will clear up some concepts for you. 
 
Another feature to try out is the code generator. While editing the UIR note the "Code" menu item.  First make sure you assign callback function names for your controls. Then use the Code Generator to generate all code and see what it produces.
 
It sounds like you'll be up to speed pretty quickly. Good luck!
 
--Ian
0 Kudos
Message 4 of 6
(4,918 Views)
Hey guys,

Thanks for your help getting me situated with the multiple panels. I've even tried the Code Generator. (It seems like cheating but when you don't know the inner workings of the programming suite it does come in handy). Anyways....

My next question is one of switching back and forth between panels. I've gotten some of the basics down on opening new panels and hiding the old ones. Right now I'm working with a selection panel that has the ability to spawn a multitude of different panels depending on which category the user chooses. To make this as user friendly as possible I want to make a "BACK" button on the off chance that a user selects the wrong category. My thought was to use DiscardPanel for the incorrect panel the user clicked on and DisplayPanel for the selection panel to come back.

The tricky part is I've created separate .UIR and .C files for each of the category panels. The selection panel contains all the propper #includes for each .H file. If I want to make just a generic "BACK" button for my category panels, where would I put the code for the button and how would I make it generic enough to be placed on each of the category panels.

My attempts at this resulted in the selection panel appearing but the category panel didn't close.
0 Kudos
Message 5 of 6
(4,870 Views)
I gave up too quickly. I found a way to make it work. It may not be correct or a "pretty" work-around, but...it works.

What I did:

I made a "BACK" button on the selection panel. I created a static int in the .C file for the selection panel called "category." This int became the way that I loaded each category panel
i.e. category = LoadPanel (0, ".UIR", PanelID)
I made the "BACK" button hidden and put the Discard/Display code behind it.

Then I copy/pasted the button to each category panel (taking off the hidden option of course). Since each of the category buttons has a #include selectionpanel.h they will pull the code for the button from the category panel which was generically named and coded enough that it worked!
0 Kudos
Message 6 of 6
(4,868 Views)