📄 ini.c
字号:
}
else if (Ini_GetPointerToRawString (g_myInifile,
sectionName, itemName, &stringValue)
> 0)
{
SetCtrlVal (panelHandle, PANEL_ITEM_TYPE, 4);
SetCtrlAttribute (panelHandle,
PANEL_ITEM_VALUE_STRING,
ATTR_VISIBLE, 1);
SetCtrlAttribute (panelHandle,
PANEL_ITEM_VALUE_NUMERIC,
ATTR_VISIBLE, 0);
SetCtrlVal (panelHandle, PANEL_ITEM_VALUE_STRING,
stringValue);
}
else
MessagePopup ("Inifile",
"Error retrieving Inifile value.");
}
}
}
}
}
/* Set Dimming of Controls */
SetCtrlAttribute (panelHandle, PANEL_NEW_SECTION, ATTR_DIMMED,
(!g_myInifile));
SetCtrlAttribute (panelHandle, PANEL_DELETE_SECTION, ATTR_DIMMED,
(!g_myInifile) || (!sections));
SetCtrlAttribute (panelHandle, PANEL_SECTION, ATTR_DIMMED,
(!g_myInifile) || (!sections));
SetCtrlAttribute (panelHandle, PANEL_SECTION_NAME, ATTR_DIMMED,
(!g_myInifile) || (!sections));
SetCtrlAttribute (panelHandle, PANEL_TOTAL_ITEMS, ATTR_DIMMED,
(!g_myInifile) || (!sections));
SetCtrlAttribute (panelHandle, PANEL_NEW_ITEM, ATTR_DIMMED,
(!g_myInifile) || (!sections));
SetCtrlAttribute (panelHandle, PANEL_DELETE_ITEM, ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
SetCtrlAttribute (panelHandle, PANEL_ITEM, ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
SetCtrlAttribute (panelHandle, PANEL_ITEM_NAME, ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
SetCtrlAttribute (panelHandle, PANEL_ITEM_TYPE, ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
SetCtrlAttribute (panelHandle, PANEL_ITEM_VALUE_STRING , ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
SetCtrlAttribute (panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
SetCtrlAttribute (panelHandle, PANEL_TOTAL_SECTIONS, ATTR_DIMMED,
!g_myInifile);
SetCtrlAttribute (panelHandle, PANEL_TEXTMSG_VALUE, ATTR_DIMMED,
(!g_myInifile) || (!sections) || (!items));
return 0;
}
/*---------------------------------------------------------------------------*/
/* Create a new section in the INI object. */
/*---------------------------------------------------------------------------*/
int CVICALLBACK NewSection (int panel, int control, int event,
void *callbackData, int eventData1,
int eventData2)
{
int section;
int sections;
int found;
char *sectionName;
char userSectionName[MAX_NAME_SIZE];
switch (event)
{
case EVENT_COMMIT:
userSectionName[0] = 0;
if ((GenericMessagePopup ("New Section",
"Please specify name of new section",
"OK", "Cancel", "", userSectionName,
MAX_NAME_SIZE-1, 0,
VAL_GENERIC_POPUP_INPUT_STRING,
VAL_GENERIC_POPUP_BTN1,
VAL_GENERIC_POPUP_BTN2)
== VAL_GENERIC_POPUP_BTN1) && (userSectionName[0] != 0))
{
if (Ini_SectionExists (g_myInifile, userSectionName))
MessagePopup("Inifile","Error, section already exists");
else
{
/* We have to add a dummy item and then remove to create */
/* a new section */
Ini_PutString (g_myInifile, userSectionName,
"Dummy_tag_name", "");
Ini_RemoveItem (g_myInifile, userSectionName,
"Dummy_tag_name");
g_changesMade = 1;
}
sections = Ini_NumberOfSections (g_myInifile);
found = 0;
for (section = 1; (section <= sections) && (!found); section++)
{
if ((Ini_NthSectionName (g_myInifile, section,
§ionName)
>0) && (!strcmp(sectionName, userSectionName)))
found = section;
}
if (found)
{
section = found;
sections = Ini_NumberOfSections (g_myInifile);
SetCtrlAttribute (panel, PANEL_SECTION, ATTR_MAX_VALUE,
sections);
SetCtrlVal (panel, PANEL_SECTION, section);
UpdateUIR (panel);
}
}
break;
}
return 0;
}
/*--------------------------------------------------------------------------*/
/* Delete a Section from the INI object. */
/*--------------------------------------------------------------------------*/
int CVICALLBACK DeleteSection (int panel, int control, int event,
void *callbackData, int eventData1,
int eventData2)
{
char sectionName[MAX_NAME_SIZE];
switch (event)
{
case EVENT_COMMIT:
sectionName[0] = 0;
GetCtrlVal (panel, PANEL_SECTION_NAME, sectionName);
if (!Ini_RemoveSection (g_myInifile, sectionName))
MessagePopup("Inifile","Error removing item from section");
UpdateUIR(panel);
g_changesMade = 1;
break;
}
return 0;
}
/*--------------------------------------------------------------------------*/
/* Change which Section is currently displayed. */
/*--------------------------------------------------------------------------*/
int CVICALLBACK ChangeCurrentSection (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
if (event == EVENT_COMMIT)
UpdateUIR (panel);
return 0;
}
/*--------------------------------------------------------------------------*/
/* Create a new Item in the INI object. */
/*--------------------------------------------------------------------------*/
int CVICALLBACK NewItem (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int item;
int items;
int found;
char *itemName;
char sectionName[MAX_NAME_SIZE];
char userItemName[MAX_NAME_SIZE];
switch (event)
{
case EVENT_COMMIT:
userItemName[0] = 0;
if ((GenericMessagePopup ("New Item",
"Please specify name of new item",
"OK", "Cancel", "", userItemName,
MAX_NAME_SIZE-1, 0,
VAL_GENERIC_POPUP_INPUT_STRING,
VAL_GENERIC_POPUP_BTN1,
VAL_GENERIC_POPUP_BTN2)
== VAL_GENERIC_POPUP_BTN1) && (userItemName[0] != 0))
{
GetCtrlVal (panel, PANEL_SECTION_NAME, sectionName);
if (Ini_ItemExists (g_myInifile, sectionName, userItemName))
{
MessagePopup ("Inifile", "Error, item already exists");
goto Error;
}
Ini_PutString (g_myInifile, sectionName, userItemName, "");
g_changesMade = 1;
items = Ini_NumberOfItems (g_myInifile, sectionName);
found = 0;
for (item = 1; (item <= items) && (!found); item++)
{
if ((Ini_NthItemName (g_myInifile, sectionName, item,
&itemName)
> 0) && (!strcmp (itemName, userItemName)))
found = item;
}
if (found)
{
item = found;
items = Ini_NumberOfItems (g_myInifile, sectionName);
SetCtrlAttribute (panel, PANEL_ITEM, ATTR_MAX_VALUE,
items);
SetCtrlVal (panel, PANEL_ITEM, item);
UpdateUIR (panel);
}
}
break;
}
Error:
return 0;
}
/*--------------------------------------------------------------------------*/
/* Delete an Item from the INI object. */
/*--------------------------------------------------------------------------*/
int CVICALLBACK DeleteItem (int panel, int control, int event,
void *callbackData, int eventData1,
int eventData2)
{
char sectionName[MAX_NAME_SIZE];
char itemName[MAX_NAME_SIZE];
switch (event)
{
case EVENT_COMMIT:
sectionName[0] = 0;
itemName[0] = 0;
GetCtrlVal (panel, PANEL_SECTION_NAME, sectionName);
GetCtrlVal (panel, PANEL_ITEM_NAME, itemName);
if (!Ini_RemoveItem (g_myInifile, sectionName, itemName))
MessagePopup("Inifile", "Error removing item from section");
UpdateUIR (panel);
g_changesMade = 1;
break;
}
return 0;
}
/*--------------------------------------------------------------------------*/
/* ChangeCurrentItem */
/*--------------------------------------------------------------------------*/
int CVICALLBACK ChangeCurrentItem (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event) {
case EVENT_COMMIT:
UpdateUIR (panel);
break;
}
return 0;
}
/*--------------------------------------------------------------------------*/
/* QuitCallback */
/*--------------------------------------------------------------------------*/
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event) {
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -