//*********************************************************
// Labwindows/cvi8.5 工具栏的提示
// 从外部.ini 文件读取提示信息
// szlihongtao
// 2010-08-23
//*********************************************************
#include <formatio.h>
#include <cvirte.h>
#include <utility.h>
#include "inifile.h"
#include <userint.h>
#include "toolbar.h"
#include "tool bar.h"
//*********************************************************
static int panelHandle;
static ToolbarType filetoolbar;
char filename[MAX_PATHNAME_LEN];
//*********************************************************
//自定义函数声明
void gettoolbar(void);
void set_tip(void);
//*********************************************************
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "tool bar.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
gettoolbar();
set_tip();
RunUserInterface ();
DiscardPanel (panelHandle);
CloseCVIRTE ();
return 0;
}
//*********************************************************
int CVICALLBACK panelCB (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
switch (event)
{
case EVENT_CLOSE:
QuitUserInterface (0);
break;
}
return 0;
}
//*********************************************************
void set_tip(void)
{
int i,status;
long FileSize;
char *stringValue;
IniText g_myInifile = 0;
const char Section_Name[]="tip";
const char *Tag_Name[]={"tip0 ","tip1 ","tip2","tip3","tip4"};
GetProjectDir (filename);
strcat (filename, "\\tip.ini"); // 完整的文件名
//if (GetFileInfo("tip.ini" ,&FileSize)==TRUE) // 文件存在?
if (GetFileInfo(filename ,&FileSize)==TRUE) // 文件存在?
{
if (!(g_myInifile = Ini_New (0))) /* Create a new Inifile object and read it from a file */
{
MessagePopup("Inifile","Error allocating memory for Inifile,无法在内存中定位文件!");
return ;
}
if (Ini_ReadFromFile (g_myInifile, filename))
{
MessagePopup("Inifile","Error reading Inifile,无法读取ini文件!");
return ;
}
for(i=0;i<5;++i)
{
status=Ini_GetPointerToRawString (g_myInifile,Section_Name, Tag_Name, &stringValue);
/*
函数原型: int Toolbar_SetItemAttribute (ToolbarType Toolbar, int Position, int Toolbar_Item_Attribute, ...);
Position : The position of the item in the toolbar.
Valid positions are from 1 to the number of items on the toolbar (as returned by Toolbar_GetNumItems).
You may also use FRONT_OF_LIST or END_OF_LIST to specify the beginning or the end of the list, respectively.
position从1开始计数
*/
if (status>0)
Toolbar_SetItemAttribute (filetoolbar, i+1, TOOLBAR_ATTR_DESCRIPTION,stringValue);
}
Ini_Dispose (g_myInifile);
}
else
MessagePopup ("提示", "tip.ini文件不存在");
}
//*********************************************************
//自定义函数,装载工具栏
//*********************************************************
void gettoolbar(void)
{
//新建“文件”工具栏
Toolbar_New (panelHandle, 0, "文件", 0, 0, 1, 1, &filetoolbar);
//插入菜单按钮
Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "新建", kNoCallback, 0, 0, 0, "new.ico");
Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "打开", kNoCallback, 0, 0, 0, "open.ico");
Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "保存", kNoCallback, 0, 0, 0, "save.ico");
Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "打印", kNoCallback, 0, 0, 0, "print.ico");
Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "退出", kNoCallback, 0, 0, 0, "exit.ico");
//显示工具栏
Toolbar_Display (filetoolbar);
Toolbar_SetAttribute (filetoolbar, TOOLBAR_ATTR_BUTTON_IMAGE_SIZE, 32);
}
//*********************************************************
//*********************************************************
//*********************************************************
文章评论(0条评论)
登录后参与讨论