LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Panel Handles and Callbacks

Solved!
Go to solution

I'm having some issues with panel handles and callbacks, I think I may be misunderstanding exactly what consititues a "panel."

 

My program only has a single panel with three tabs, i.e. the Panels and Controls section of my .h file looks like this:


#define  PANEL                            1       /* callback function: panelCB */
#define  PANEL_TAB                   2

 

My issue comes in callbacks when I try to set or get control values, I have a command button callback that looks like this:

 

int CVICALLBACK StartLoggingClicked (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_COMMIT:
            SetTabPageAttribute (panelHandle, PANEL_TAB, 0, ATTR_DIMMED, 1);
            SetTabPageAttribute (panelHandle, PANEL_TAB, 1, ATTR_DIMMED, 1);
           
            SetCtrlAttribute(panel, TAB_MON_COMMAND_PAUSEMON, ATTR_DIMMED, 0);
            SetCtrlAttribute(panel, TAB_MON_COMMAND_STOPMON, ATTR_DIMMED, 0);

            break;
    }
    return 0;
}

 

panelHandle is the global variable assigned by the call to LoadPanel. When I watch the values panel and panelHandle they are different (i.e., panelHandle =1, panel=4). Coincidentally (or not...) 4 is the value assigned to the command button in the .h file.

 

If I do: SetTabPageAttribute(panel, PANEL_TAB, 0, ATTR_DIMMED, 1)

I get a "The control is not the type expected by the function" error, but it works fine with the global panelHandle.

 

If I do: SetCtrlAttribute(panelHandle, TAB_MON_COMMAND_PAUSEMON, ATTR_DIMMED, 0);

I get an "Invalid control ID" error, but it works with the callback parameter "panel".

 

I have another section of code in a function called by the callback:

GetCtrlVal (panelHandle, TAB_BOARD_STRING_DATAFILENAME, &t_LogFilePath);

That gives the error "The control does not have a value"

If I pass the callback value of "panel" to the function and do:

GetCtrlVal (panel, TAB_BOARD_STRING_DATAFILENAME, &t_LogFilePath);

I get "Invalid arugment type: found 'pointer to array 260 of char', expected 'pointer to int'

 

It looks to me like the values of panel and panelHandle don't correspond to exactly what I think they do because it appears the control values I'm passing are wrong (i.e. don't correspond to the correct panel) in some cases. Any help would be greatly appreciated.

I've searched for more details on what does and does not consititue a panel to try and figure out why I'm seeing different values, but I haven't found anything. If there's a reference I've missed please point me to it.

0 Kudos
Message 1 of 7
(5,564 Views)

I would assume that you should not define the UI constants yourself but include the UI-h-file where these constants are already declared...

 

Wolfgang

0 Kudos
Message 2 of 7
(5,559 Views)

Thanks for the repsonse. The UI .h file is included and I'm not manually defining any of the UI constants. The .h file only contains the values automatically generated based on the .uir file.

Message Edited by AndrewGND on 02-24-2009 11:03 AM
0 Kudos
Message 3 of 7
(5,557 Views)
Solution
Accepted by topic author AndrewGND

Here we are in the typical issue everyone who uses a tab control falls in. To be telegraphic,

 each and every page of a tab control acts (actually is) a separate panel with its own handle to be used when addressing control on the tab page itself.

 

To be more clear, the tab is a control on your main panel, and addressing the tab control must be made with the handle of the main panel (panelhandle in your case): this is true for example when using SetTabPageAttribute or GetTabPageAttribute or when setting / retrieving attributes of the tab control itself (ATTR_TOP and so on); this is true also if you want to operate on the tab control with InsertTabPage, CopyTabPage and so on.

 

On the other hand, before addressing a control on a tab page, you must retrieve the proper panel handle of the tab page itself, for example by using GetPanelHandleFromTabPage. With that handle you can address controls located on the tab page. Only in case your callback fires from a control on a tab page and wants to act on another control on the same page, you can use 'panel', i.e. the first parameter in the control callback: this is a case when the callback of a button on the tab page needs to read the value of a control on the same page. But if your button is located elsewhere (out of the tab control or on another page of the tab) you need to retrieve the correct handle before attempting to address a control: failing to do so will result in the errors you are finding and some more you haven't found yet. Smiley Wink

 

The TabExample sample shipped with CVI (<cvidir>\samples\userint folder) can be useful to deep in tab control usage.



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 4 of 7
(5,555 Views)
Thanks Roberto! That clears everything up.
0 Kudos
Message 5 of 7
(5,546 Views)
You're welcome!


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 7
(5,541 Views)

kudos!

 

thank you.  that helped a lot.  that fixed my problem.

 

GetPanelHandleFromTabPage!

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