LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

checking from which panel was the command button pressed

Hi,
 
I was wondering if someone can help me out with my current problem. Basically i am trying to figure a way to find out from which panel was the button with the same callback was pressed. say for example i want to print the panel....thus i hv print command button in all panels(each panel has a different handle) but they all go to the same callback....now here i want to check which panel it was pressed from so that i can pass the correct handle n thus prints that panel.
 
hope to hear from someone soon.
 
Thanks
 
k1_ke
0 Kudos
Message 1 of 7
(4,073 Views)

It depends on how you structure your application but if you have stored the panel handles in a central location you can compare the value for panel passed to the callback to the available list of panel handles.

Another method is calling GetPanelAttribute(panel, ATTR_CONSTANT_NAME, charBuffer); will return the constant name that was used when you called LoadPanel() you can use a switch statement (if the panels have a unique character) or some other comparison method to determine which panel was the caller. 

Yet another is to call GetPanelAttribute(panel, ATTR_TITLE, charBuffer); This will get the panel title as a character string and again a switch statement or other comparison may be the way to go. This method is useful when you dynamically create panels.

 

 

Message Edited by mvr on 03-29-2006 01:20 PM

0 Kudos
Message 2 of 7
(4,064 Views)

Well, in your particular application, the handle of the panel is the first parameter received from the callback! So you can simply pass "panel" variable to PrintPanel function to obtain an hard copy of your panel.

This supposing that the Print button is on the same panel that is to be printed as I seem to understand.

The solutions proposed from mvr are useful if you load only one instance of your panels: supposing you load two instances of one panel the constant name is the same for both of them, and the same will be the title provided that you don't personalize it after loading the panel. But if you are not in this situation you can indeed use those attributes.



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 7
(4,059 Views)

Thanks mvr and Roberto,

Yeah i was able to solve my problem using roberto's method. i had a button on each panel that i wanted to print and thus passing panel worked for me....but what i dont understand is that hw come even though each panel hv its own unique name but by passing "panel" took the panelhandle of the panel from which i pressed the button and printed it.

Thanks once again

k1_ke

0 Kudos
Message 4 of 7
(4,050 Views)
Roberto,
Thanks for pointing out the simpler solution.  I went right past that one while thinking that each panel must need to do something unique before calling PrintPanel.  Sometimes the simpler solutions are harder to find.
0 Kudos
Message 5 of 7
(4,048 Views)

K1_ke > When you load a panel, you obtain an handle to that panel, which is unique throughout the application. Supposing you load the same panel twice, you will get two different handles for them.

This handle is then automatically passed by the system to the callbacks for all objects on that panel: the panel itself, all controls and all menu items that are on it. This handle is passed in the first variable for panel and control collbacks, and in the last for menu callbacks. It's this handle that permits you to discriminate which panel and/or control has fired the callback, so that you can manpiulate this control and other controls on the same panel without need to retain global variables for all of them. This process is called "incapsulation": a function receives as its parameters all the variables that it needs to use. This permits to reduce the need for global variables, that in a multi-threaded executing environment are dangerous since another thread can modify their contents before the function has used them. If received in the function call, the parameters are unique to this function and nobody can alter them.

In control callback, "panel" identifies and defines and (integer) variable that holds the panel handle, the same as "control" is a variable that holds the control ID. This is the reason why you can use one callback for several controls on a panel and for controls on different panels: a simple switch () on the appropriate variable can be used to discriminate the control that has fired the callback:

Message Edited by Roberto Bozzolo on 03-29-2006 11:07 PM



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

Hi Roberto,

Thank you soo much for the clear explanation. Now everything makes sense.

really appreciated!

Thanks

k1_ke

0 Kudos
Message 7 of 7
(4,011 Views)