ColorChangePopup
int ColorChangePopup (const char title[], ListType colorList, int showDefaultButton, ShowColorChangeFunction colorChangeCallback, void *colorChangeCallbackData);
Purpose
This function displays a dialog which presents the user with a list of named colors and allows the user to change the values of these colors.
The dialog is similar in appearance and function to the Environment Color Preferences dialog box in the LabWindows/CVI environment.
Example Code
The following code can be run in the interactive window to demonstrate the ColorChangePopup:
/* Note: Since this example does not pass in a color change
callback, the color selections will not be applied to
anything.*/
#include "toolbox.h"
static ColorChangeEntry entry;
static ListType colorList = 0;
static int result;
colorList = ListCreate(sizeof(ColorChangeEntry));
entry.name = "Cat Color";
entry.color = VAL_RED;
entry.defaultColor = VAL_BLUE;
ListInsertItem(colorList, &entry, END_OF_LIST);
entry.name = "Dog Color";
entry.color = VAL_GREEN;
entry.defaultColor = VAL_CYAN;
ListInsertItem(colorList, &entry, END_OF_LIST);
result = ColorChangePopup("Select Colors", colorList, 1, 0, 0);
ListDispose(colorList);
if (result > 0)
MessagePopup("Color Change Result", "A Color Was Changed");
else
if (result == 0)
MessagePopup("Color Change Result", "No Color Was Changed");
else
MessagePopup("Color Change Result", "An Error Occurred");
Parameters
Input | ||
Name | Type | Description |
title | const char[] | Specifies the title of the color change dialog. |
colorList | ListType | The color list should be a list of ColorChangeEntry structures.
Each ColorChangeEntry struct defines the name of a color, its default value (in RGB), and its current value (in RGB). Each ColorChangeEntry struct in the list will be represented by an entry in the list box on the color change dialog. The ColorChangeEntry struct has the following form (as defined in toolbox.h): typedef struct
{ Color List Hints: Use ListCreate(sizeof(ColorChangeEntry)) to create the list. Use ListInsertItem to insert ColorChangeEntry structures. |
showDefaultButton | int | Specify a nonzero value or select On to add the default button to the color change popup. If you press the default button, each color reverts to the default value specified by the color's entry in the colorList. Specify 0 or select Off to omit the default button. |
colorChangeCallback | ShowColorChangeFunction | This parameter specifies a callback function that the color change dialog will call when a color is changed in the dialog. This callback function should respond by applying the current values of the colors in the colorList it is passed. This allows the user to see the result of their color changes before exiting the dialog. The callback function must have the following prototype: void CVICALLBACK ShowColorChangeFunction(ListType color_List, void *color_Change_Callback_Data, int color_List_Index); The colorList parameter is the same list of ColorChangeEntry structures that was passed in to ColorChangePopup, except that the color field of each structure reflects any changes the user has made while operating the dialog. The colorChangeCallbackData is the same value that was passed in to ColorChangePopup. The colorListIndex parameter is the index in the colorList of the color that the user changed. If the value of colorListIndex is –1, then the value of every color in the list should be applied (this occurs when the user selects cancel or default). |
colorChangeCallbackData | void * | A pointer to user defined data that will be passed to the colorChangeCallback function. This parameter can be useful to pass information to the callback function indicating which object(s) to apply the color list to without the need to resort to global variables. If this parameter is not needed, you may pass zero (or any other value if cast as a void pointer). |
Return Value
Name | Type | Description |
result | int | Returns 0 if no changes were made, returns > 0 if changes were made, or returns a negative User Interface Library error code if an error occurred. |
Additional Information
Library: Programmer's Toolbox
Include file: toolbox\toolbox.h
LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later