?? ini.c
字號(hào):
/*--------------------------------------------------------------------------*//* Inifile instrument driver example *//*--------------------------------------------------------------------------*/#define HELP_MSG \"This example shows how to use the functions in the Inifile instrument\n\driver. The Inifile instrument driver contains functions to:\n\\n\ - create and dispose an object which can contain an in-memory\n\ list of tag/value pairs.\n\ - sort the in-memory list of tag/value pairs\n\ - read a list of tag/value pairs from a file\n\ - write the in-memory list of tag/value pairs to a file\n\\n\This example opens an existing *.ini file and allows you to display,\n\add, and remove sections and items from the inifile.\n\\n\Note: The Inifile instrument driver treats empty tag items as if they\n\are not defined. For example, if the Ini file contains,\n\ [Ports]\n\ COM1 = 9600\n\ COM2 =\n\the COM2 tag will not be read in."/*--------------------------------------------------------------------------*//* Includes *//*--------------------------------------------------------------------------*//* #include <windows.h> For call to SDK function GetSystemDirectory() if used */#include <utility.h>#include <userint.h>#include "inifile.h"#include "ini.h"/*--------------------------------------------------------------------------*//* Defines *//*--------------------------------------------------------------------------*/#define MAX_NAME_SIZE 256/*--------------------------------------------------------------------------*//* Variables *//*--------------------------------------------------------------------------*/static int panelHandle = 0;static int changesMade = 0;static IniText myInifile = 0;static char fileName[MAX_PATHNAME_LEN];/*--------------------------------------------------------------------------*//* Prototypes *//*--------------------------------------------------------------------------*/int UpdateUIR(void); /*--------------------------------------------------------------------------*//* Main *//*--------------------------------------------------------------------------*/int main (int argc, char *argv[]){ int status; if (InitCVIRTE (0, argv, 0) == 0) /* Initialize CVI libraries */ return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, "ini.uir", PANEL)) < 0) return -1; DisplayPanel (panelHandle); /* Use Browse button callback to ask for initial file */ FilenameBrowse (panelHandle, PANEL_FILENAME_BROWSE, EVENT_COMMIT, 0, 0, 0); RunUserInterface (); /* Write file back out */ if ((myInifile) && (changesMade)) { if (ConfirmPopup ("Save Changes", "Do you want to save changes before opening new file?")) { Ini_WriteToFile (myInifile, fileName); } } /* Destroy Inifile */ if (myInifile) { Ini_Dispose (myInifile); myInifile = 0; } changesMade = 0;Leave: return 0;}/*--------------------------------------------------------------------------*//* FilenameBrowse *//*--------------------------------------------------------------------------*/int CVICALLBACK FilenameBrowse (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_COMMIT: /* Ask user which Inifile to open */ fileName[0] = 0; /* GetSystemDirectory(fileName, MAX_PATHNAME_LEN); */ if (FileSelectPopup (fileName, "*.ini", "*.ini", "Specify INI file to open", VAL_LOAD_BUTTON, 0, 0, 1, 1, fileName)!=VAL_EXISTING_FILE_SELECTED) return 0; /* Write file back out */ if ((myInifile) && (changesMade)) { if (ConfirmPopup ("Save Changes", "Do you want to save changes before opening new file?")) { Ini_WriteToFile (myInifile, fileName); } } /* Destroy Inifile */ if (myInifile) { Ini_Dispose (myInifile); myInifile = 0; } changesMade = 0; /* Create Inifile List */ if (!(myInifile = Ini_New (0))) { MessagePopup("Inifile","Error allocating memory for Inifile"); goto Leave; } /* Open file */ if (Ini_ReadFromFile (myInifile, fileName)) { MessagePopup("Inifile","Error reading Inifile"); goto Leave; } SetCtrlVal(panelHandle, PANEL_FILENAME, fileName); UpdateUIR(); break; } return 0; Leave: if (myInifile); Ini_Dispose (myInifile); return 0;}/*--------------------------------------------------------------------------*//* UpdateUIR *//*--------------------------------------------------------------------------*/int UpdateUIR(void){ int sections = 0, items = 0; int section = 0, item = 0; char *sectionName = NULL; char *itemName = NULL; int booleanValue; int integerValue; double doubleValue; char *stringValue; if (myInifile) { /* Set total section information */ sections = Ini_NumberOfSections (myInifile); SetCtrlVal(panelHandle, PANEL_TOTAL_SECTIONS, sections); SetCtrlAttribute(panelHandle, PANEL_SECTION, ATTR_MIN_VALUE, (sections>0)); SetCtrlAttribute(panelHandle, PANEL_SECTION, ATTR_MAX_VALUE, sections); /* Set sections and item information */ if (sections) { GetCtrlVal(panelHandle, PANEL_SECTION, §ion); Ini_NthSectionName (myInifile, section, §ionName); if (sectionName) { SetCtrlVal(panelHandle, PANEL_SECTION_NAME, sectionName); items = Ini_NumberOfItems (myInifile, sectionName); SetCtrlVal(panelHandle, PANEL_TOTAL_ITEMS, items); SetCtrlAttribute(panelHandle, PANEL_ITEM, ATTR_MIN_VALUE, (items>0)); SetCtrlAttribute(panelHandle, PANEL_ITEM, ATTR_MAX_VALUE, items); /* Set item information */ if (items) { GetCtrlVal(panelHandle, PANEL_ITEM, &item); Ini_NthItemName (myInifile, sectionName, item, &itemName); if (itemName) { SetCtrlVal(panelHandle, PANEL_ITEM_NAME, itemName); if (Ini_GetBoolean (myInifile, sectionName, itemName, &booleanValue)>0) { SetCtrlVal(panelHandle, PANEL_ITEM_TYPE, 1); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_STRING, ATTR_VISIBLE, 0); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_VISIBLE, 1); SetCtrlAttribute (panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_DATA_TYPE, VAL_INTEGER); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_MIN_VALUE, 0); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_MAX_VALUE, 1); SetCtrlVal(panelHandle, PANEL_ITEM_VALUE_NUMERIC, booleanValue); } else if (Ini_GetInt (myInifile, sectionName, itemName, &integerValue)>0) { SetCtrlVal(panelHandle, PANEL_ITEM_TYPE, 2); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_STRING, ATTR_VISIBLE, 0); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_VISIBLE, 1); SetCtrlAttribute (panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_DATA_TYPE, VAL_INTEGER); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_MIN_VALUE, -2147483647); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_MAX_VALUE, 2147483647); SetCtrlVal(panelHandle, PANEL_ITEM_VALUE_NUMERIC, integerValue); } else if (Ini_GetDouble (myInifile, sectionName, itemName, &doubleValue)>0) { SetCtrlVal(panelHandle, PANEL_ITEM_TYPE, 3); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_STRING, ATTR_VISIBLE, 0); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_VISIBLE, 1); SetCtrlAttribute (panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_DATA_TYPE, VAL_DOUBLE); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_MIN_VALUE, -HUGE_VAL); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_MAX_VALUE, HUGE_VAL); SetCtrlVal(panelHandle, PANEL_ITEM_VALUE_NUMERIC, doubleValue); } else if (Ini_GetPointerToRawString (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 value from Inifile for item"); } } } } } } /* Set Dimming of Controls */ SetCtrlAttribute(panelHandle, PANEL_NEW_SECTION , ATTR_DIMMED, (!myInifile)); SetCtrlAttribute(panelHandle, PANEL_DELETE_SECTION , ATTR_DIMMED, (!myInifile) || (!sections)); SetCtrlAttribute(panelHandle, PANEL_SECTION , ATTR_DIMMED, (!myInifile) || (!sections)); SetCtrlAttribute(panelHandle, PANEL_SECTION_NAME , ATTR_DIMMED, (!myInifile) || (!sections)); SetCtrlAttribute(panelHandle, PANEL_TOTAL_ITEMS , ATTR_DIMMED, (!myInifile) || (!sections)); SetCtrlAttribute(panelHandle, PANEL_NEW_ITEM , ATTR_DIMMED, (!myInifile) || (!sections)); SetCtrlAttribute(panelHandle, PANEL_DELETE_ITEM , ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); SetCtrlAttribute(panelHandle, PANEL_ITEM , ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); SetCtrlAttribute(panelHandle, PANEL_ITEM_NAME , ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); SetCtrlAttribute(panelHandle, PANEL_ITEM_TYPE , ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_STRING , ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); SetCtrlAttribute(panelHandle, PANEL_ITEM_VALUE_NUMERIC, ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); SetCtrlAttribute(panelHandle, PANEL_TOTAL_SECTIONS , ATTR_DIMMED, (!myInifile)); SetCtrlAttribute(panelHandle, PANEL_TEXTMSG_VALUE , ATTR_DIMMED, (!myInifile) || (!sections) || (!items)); /* status = Ini_GetBoolean (myInifile, sectionName, itemName, booleanValue);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -