LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ToolBar Callback

Hi,

I'm trying to use a toolbar callback as below:

ToolBarCallback(int panel, int toolBarId, int event, void *callbackData, int eventData1, int eventData2)

I have two toolbars on two tabbed panels, I am trying to use one callback for both toolbars.

The problem I have is when the callback is called, I found the toolbarId is the same for both toolbars
and also the panelhandle doesn't associate with any of my panels.
What am I doing wrong???

Thanks
James
0 Kudos
Message 1 of 5
(3,584 Views)
Hi James,
could you please post the example code as stripped down as possible, and the version of LabWindows/CVI that you're using.

Thanks
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 2 of 5
(3,527 Views)
Hi James,
I've just knocked up some test code, and verified what you're seeing with the toolBarID. I'm investigating this with our developers in the US.
The Panel bit is actually a case of it returning the panel that the toolbar is embedded in, and not the parent panel to that.
Use :
int parentPanel = -1;
GetPanelAttribute (panel, ATTR_PANEL_PARENT, &parentPanel);

to return the actual panelHandle

I've also done a temporary workaround for finding the toolBarID. You can pass it through the callback data. It then takes a little typecasting within the callback to strip it out to something useful.

Please see the attached zip file with the CVI 7.1 project in it.

Hope that helps

Thanks
Sacha Emery
National Instruments (UK)
// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 3 of 5
(3,513 Views)
The actual problem here is that the documentation for the toolbar API indicates implicitly through the prototype of the control callback function that the second parameter will be the toolBarId, when in fact, the toolbar code is passing the control ID of the corresponding control on the toolbar. I'm not certain which behavior was intended, but it does explain why the value is the same for both toolbars; they each have one control so naturally they will have the same control ID associated with them. Also note that this control ID is the UI handle for the control on the toolbar panel and is not related to the control index you pass to functions such as Toolbar_DimItem and Toolbar_SetItemAttribute.

The proposed workaround (to simply use the callback data to pass on the ToolbarType of the associated toolbar) seems like a good workaround.

Sorry for the confusion.

Alex
0 Kudos
Message 4 of 5
(3,501 Views)
Hi,
  just to close things off here a little, in LabWindows/CVI 8.0 we've changed the parameters
 
Instead of

int CVICALLBACK ToolBarCallback(int panel, int toolBarId, int event, void *callbackData, int eventData1, int eventData2);

the callback prototype is now

int CVICALLBACK ToolbarItemCallback(int toolbar, int toolbarItemIndex, int event, void *callbackData, int eventData1, int eventData2);

(Callbacks used when inserting a new item into the toolbar)

Also in LabWindows/CVI 8.0 there's a callback for the entire toolbar :

Toolbar_InstallCallback (ToolbarType Toolbar, ToolbarCallbackPtr Callback_Function, void *Callback_Data);

the callback function for which takes the prototype :

int ToolbarCallback (ToolbarType toolbar, int event, void *callbackData, int eventData1, int eventData2);
where the events are :

TOOLBAR_EVENT_DOCK
TOOLBAR_EVENT_UNDOCK
TOOLBAR_EVENT_SIZE
TOOLBAR_EVENT_ARRANGE

so you can track when things happen on the toolbar in general now since it's been expanded somewhat in functionality.

Thanks

Sacha Emery
National Instruments (UK)

// it takes almost no time to rate an answer Smiley Wink
0 Kudos
Message 5 of 5
(3,366 Views)