LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute code when a panel OPENs or LOADs?

I want to execute code when a Panel is opened or loaded for the first time, but I cannot see a way to  do this.
I can generate a CALLBACK for the Panel with various EVENT options, and there seems to be everything but what I want, like DISCARD, CLOSE, SIZE, MOVE, GOT FOCUS, LOST FOCUS etc, but no OPEN or LOAD!
 
GOT_FOCUS seems to be the closest option, but I don't want the code to execute when I simply move focus from one open window to the next.
 
Am I missing something obvious?
 
I could put the code (or a function) before I call every Load Panel command but that's not a neat and modular way to do it.
 
Thanks
Dave 🙂
0 Kudos
Message 1 of 6
(4,095 Views)
Unfortunately I see now way to do this with the help of any EVENTS, because there are no load or unload-events for CVI panels. So the only chance to do this is to write a function, that initializes and loads the panel(LoadPanel), and call this function instead of the LoadPanel function in your code.
0 Kudos
Message 2 of 6
(4,086 Views)

A workoround for panel_load event: put in the panel a timer control enabled and with interval = 0.

Immediately after the panel load the timer should execute its callback: in the callback do what you need for the panel_load event and then disable the timer so that its callback is executed only once.

Otherwise, you could simplify your code by creating your own function for panel loading.

int MyLoadPanel (int Parent_Panel_Handle, char Filename[],
               int Panel_Resource_ID, ctrlCallbackPtr LoadCallback);

Then you can call MyLoadPanel instead of traditional function where a special callback has to run after panel loading.



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 3 of 6
(4,083 Views)

Neat trick, thanks!

It's shear madness though that there is no LOAD event, anyone know why?

Dave 🙂

0 Kudos
Message 4 of 6
(4,063 Views)
Dave,
 
The general theory behind events is to notify the developer of something that they could not otherwise know about. For example, users moving/sizing the window, clicking with the mouse, pressing keys, etc. This is not a hard and fast rule (ex. EVENT_DISCARD cannot happen due to normal user interaction, however you can destroy child panels and controls by discarding the panel they reside in, so this is still a useful event to make code cleanup more straightforward). For this reason, since loading is something that can only happen programatically and cannot really happen unexpectedly, it's assumed that you know about it and can do whatever needs doing.
 
Regards,
 
-alex
0 Kudos
Message 5 of 6
(4,045 Views)

Fair enough, and makes sense when you think abut it I guess, but as a result the code will always be a bit messier and non-consitent across different developers. Coming from a VB background I find this limitation rather annoying.

Thanks
Dave 🙂

0 Kudos
Message 6 of 6
(4,029 Views)