Change Color of DAQmx Physical I/O Channel Control in LabWindows/CVI

Updated Jun 20, 2023

Environment

Software

  • LabWindows/CVI

Driver

  • NI-DAQmx

Operating System

  • Windows

This article explains the methods for altering the color of all parts of a DAQmx Physical Channel control to allow for better integration of the control into a program's UI. The DAQmx Physical Channel control present in the  LabWindows/CVI example ContAcq-IntClk-AnlgStart.prj is used as the model for the techniques described.

Image highlighting the type of control discussed in the article.
 

The exact method to edit the color of the DAQmx Physical channel Control will change depending on the portion of the control you're looking to edit, though most methods will involve using the SetCtrlAttribute() function.

Text Background

To change the background color of the selected menu option text on the DAQmx Physical Channel control, you can edit the Text Background Color attribute using the below commands:
int color = MakeColor(R, G, B);
SetCtrlAttribute(panelHandle, PANEL_CHANNEL, ATTR_TEXT_BGCOLOR, color);

where panelHandle corresponds to the panel ID of the panel the DAQmx Physical Channel control is located on and CHANNEL is the control ID of the Ring control being used to create the DAQmx Physical Channel. If the color we make using the MakeColor function is red (255,0,0), we would get the below results:

Image showing the results of modifying the DAQmx Physical Channel Control's Text Background Color.

Arrow

The process to modify the color of a DAQmx Physical Channel control's arrow is more complex, as the function used to create a DAQmx Physical Channel control based on a String control (NIDAQmx_NewPhysChanAICtrl for Analog Input channels) creates new UI controls at runtime that overlay on top of the existing String control. In order to edit the Arrow color, we need to determine the control ID for one of these newly created components.

When NIDAQmx_NewPhysChanAICtrl runs, it creates two control types - a CTRL_RECESSED_BOX (control style 396), and a CTRL_POPUP_MENU_RING_LS (control style 322). These controls are used to create the Ring overlay on the String control used as the base for the DAQmx Physical Channel control. These controls have empty constant names, and will generally be among the last controls created by your code during panel setup. Using this information, we can search through our list of controls to find the control ID which corresponds to the CTRL_POPUP_MENU_RING_LS created by NIDAQmx_NewPhysChanAICtrl, which is needed to change the color of the control's arrow.

The below code snippet is a generic method which searches through your panel's list of controls following the creation of a DAQmx Physical Channel control, finds the control ID of the created CTRL_POPUP_MENU_RING_LS control, and changes the color of the control's arrow. You will need to include the string.h header in your .c file to execute this code.

NIDAQmx_NewPhysChanAICtrl(panelHandle,PANEL_CHANNEL,1);
	//Declare color and necessary variables
	int color = MakeColor ( 255, 0, 0); 
	int ctrlID;
	int numCtrl;
	int ctrlStyle;
	char constantName[256];
	int compVal;
	//Get ID of first control and total number of controls
	GetPanelAttribute(panelHandle, ATTR_PANEL_FIRST_CTRL, &ctrlID);
	GetPanelAttribute(panelHandle,ATTR_NUM_CTRLS, &numCtrl);
	//Iterate through controls until last control ID is reached - note that
	// numCtrl-1 is used as our upper limit because iterating through to the
	//last control will return 0 as the control ID, signifying the end of the
	//list.
	for(int i=0; i<numCtrl-1; i++) {
		GetCtrlAttribute(panelHandle, ctrlID, ATTR_NEXT_CTRL, &ctrlID);
		//Get current control's name, and compare it to an empty string.
		GetCtrlAttribute(panelHandle, ctrlID, ATTR_CONSTANT_NAME, constantName);
		compVal = strcmp(constantName, "");
		//If there is a match, then the current control is one of the controls
		//created by NIDAQmx_NewPhysChanAICtrl. Compare its control style
		//to the style of the control we're looking for (322).
		if (compVal == 0) {
			GetCtrlAttribute(panelHandle, ctrlID, ATTR_CTRL_STYLE, &ctrlStyle);
			//If there is a match, break out of the search.
			if (ctrlStyle == 322) {
				break;
			}
		}
	}
	//Set the arrow to the appropriate color
	SetCtrlAttribute(panelHandle, ctrlID, ATTR_MENU_ARROW_COLOR, color);


Executing the above code during your program's initialization will result in the following color change for your DAQmx Physical Channel control's arrow:

Image showing results of executing arrow color change code.

Arrow Background

The process to modify the background color of a DAQmx Physical Channel control's arrow is similar to the process to modify the arrow color. You'll want to execute the same code as linked above for modifying the arrow color, but change the final command to the below line, which modifies the ATTR_FRAME_COLOR attribute, to change the color of the proper element:

	SetCtrlAttribute(panelHandle, ctrlID, ATTR_FRAME_COLOR, color);

Image showing color change as a result of arrow background color change code.

Control Frame

In order to change the color of the thin control frame around the display area of your DAQmx Physical Channel control ,you'll likely need to change the type of String control you're using to create The default, modern String control type in LabWindows/CVI, CTRL_STRING_LS, cannot have its frame outline color altered, as it derives this color from the background color of the UI. In order to alter the control frame color, you need to instead use the Classic-Style String control, CTRL_STRING, as the control you're generating your DAQmx Physical Channel control from.

Image showing menu location of CTRL_STRING_LS control type.Image showing menu location of CTRL_STRING control type.

Once you have placed the correct string control type, you can create a DAQmx Physical Channel control using NIDAQmx_NewPhysChanAICtrl (or whatever NewPhysChan command is appropriate for your DAQ task) and change the frame color using the below command and the ATTR_FRAME_COLOR attribute:

	SetCtrlAttribute(panelHandle, PANEL_CHANNEL, ATTR_FRAME_COLOR, color);


Results of editing frame color of string control used to create DAQmx Physical Channel Control.

Drop-Down Menu

The color of the drop-down menu of the DAQmx Physical Channel control is not editable using CVI control properties, as the menu's color is actually determined by Windows system settings. In older versions of Windows such as XP, 7, and some versions of 10, you can edit the drop-down menu color by navigating to Personalize->Window Color, selecting Menu as the item you're looking to edit, and editing Menu Color 1. However, on Windows 10 version 1903 and newer, customization options are much more limited, so editing the drop-down menu color is not possible.