LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with control IDs

I have two different panels in my program with various controls. The .h file
created by Labwindows for my .uir is partially reproduced below:

#include

#ifdef __cplusplus
extern "C" {
#endif

/* Panels and Controls: */

#define PANEL 1
#define PANEL_DATE 2
#define PANEL_FILE 3
#define PANEL_EWTR 4
#define PANEL_PROCESS 5
#define PANEL_CONVERT 6
#define PANEL_DONE 7
#define PANEL_PRINT 8
#define PANEL_SAVE 9
#define PANEL_TEXTBOX 10
#define PANEL_TEMP 11
#define PANEL_RH 12
#define PANEL_ATM 13
#define PANEL_MARKER_FREQ 14
#define PANEL_MARKER_DB 15
#define PANEL_MARKER_MIN 16
#define PANEL_MARKER_MAX 17
#define PANEL_MARKER_RIGHT 18
#define PANEL_MARKER_LEFT 19
#define PANEL_GRAPH 20
#define PANEL_SCALE 21
#define PANEL_MARKER 22
#define PANEL_TEXTMSG_3 23
#define PANEL_TEXTMSG_4 24
#define PANEL_TEXTMSG_2 25
#define PANEL_TEXTMSG 26

#define PANEL_2 2
#define PANEL_2_GRAPH 2
#define PANEL_2_N_5 3
#define PANEL_2_N_4 4
#define PANEL_2_N_3 5
#define PANEL_2_N_2 6
#define PANEL_2_N_1 7
#define PANEL_2_LED_5 8
#define PANEL_2_LED_4 9
#define PANEL_2_LED_3 10
#define PANEL_2_LED_2 11
#define PANEL_2_LED_1 12
#define PANEL_2_DONE 13
#define PANEL_2_MARKER_FREQ 14
#define PANEL_2_MARKER_DB 15
#define PANEL_2_MARKER_MIN 16
#define PANEL_2_MARKER_MAX 17
#define PANEL_2_MARKER_RIGHT 18
#define PANEL_2_MARKER_LEFT 19
#define PANEL_2_PRINT 20
#define PANEL_2_BUTTON_5 21
#define PANEL_2_BUTTON_4 22
#define PANEL_2_BUTTON_3 23
#define PANEL_2_BUTTON_2 24
#define PANEL_2_BUTTON_1 25
#define PANEL_2_CURRENT 26
#define PANEL_2_TEXTMSG_2 27
#define PANEL_2_TEXTMSG_3 28
#define PANEL_2_TEXTMSG_4 29
#define PANEL_2_TEXTMSG 30
#define PANEL_2_MARKER 31

The problem is that Labwindows has assigned the same control ID to controls
in the two panels, for example, PANEL_MARKER_MIN and PANEL_2_MARKER_MIN have
the same ID, i.e. 16. If I try to use both of these controls in the same
"case" statment, I get an error "Duplicate case label '16'." If I try to
modify the .h file manually, and change the ID for PANEL_2_MARKER_MIN to
216, there is no error and the program executes but it no longer recognizes
mouse clicks on the PANEL_2_MARKER_MIN control.

Is there some way to fix this problem? Is there a way to force Labwindows
to assign different IDs for all controls, regardless of what panel they are
in?

Thank you for your help in advance.
0 Kudos
Message 1 of 4
(3,241 Views)
"...The problem is that Labwindows has assigned the same control ID to
controls
in the two panels, for example, PANEL_MARKER_MIN and PANEL_2_MARKER_MIN have
the same ID, i.e. 16. If I try to use both of these controls in the same
"case" statment, I get an error "Duplicate case label '16'." ..."

UIR editor counts controls inside the single panel they are in. In your
example, PANEL_MARKER_MIN and PANEL_2_MARKER_MIN have the same ID 'cause
both are the 16th control in their panel, rare case but it happens...
There is no way to force UIR editor to assign specific IDs to controls,
unless you add in one panel decoration controls or text messages and put
them before the other control in 'panel order' (ctrl+t in the editor): with
that trick you put in one panel all controls star
ting with order 0 (that is,
with control ID starting from 1 in the .h file), while in the second you
have non-operative contrls with lower IDs and operative controls or
indicator with higher IDs. This is NOT a polite solution since it relies on
the number of controls in the panels: every time you add new controls to a
panel, you should manage how IDs are assigned to them in order to avoid this
problem...
The best solution is to have two nested cases in your code, first one to
manage different panels, second one to manage different controls:
switch (panel) {
case PANEL:
switch (control) {
case PANEL_MARKER_MIN:
break;
// other controls of PANEL must be put here
}
break;
case PANEL_2:
switch (control) {
case PANEL_2_MARKER_MIN:
break;
// Other controls of PANEL_2 here
}
break;
}
That way you avoid any possible confusion and control mismatching that can
c
ause bizarre beaviour to your progrma.
Hope that helps
Roberto
0 Kudos
Message 2 of 4
(3,241 Views)
The argument list in the standard argument list for a callback contains items for both
panels and controls... i.e.

int CVICALLBACK Test(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);

So within the callback function, you could use a two tier switch statment to handle the duplicate control numbering between the panels... eg:

switch (panel) {
case PANEL:
switch (control) {
case 1:
...
break;
case n:
...
break;
}
break;
case PANEL_2:
switch (control) {
case 1:
...
break;
case n:
...
break;
}
break;
}
Hope this helps...
0 Kudos
Message 3 of 4
(3,241 Views)
This laways like that in Windows : first you have to check the panel handle ( a dynamic value returned after LoadPanel() function ) and after, the control ID.
You can associate a callback function per control : so you don't have to test the panel and the control IF , if the function is associated only to one control.
0 Kudos
Message 4 of 4
(3,241 Views)