原创
Labwindows/cvi8.5 工具栏的设计
2010-6-12 21:00
3448
10
11
分类:
软件与OS
//********************************************************* // Labwindows/cvi8.5 工具栏的设计 // szlihongtao // 2010-06-12 // 参照 王建新的<Labwindows/cvi测试技术及工程应用> page296 // 稍有改写 //********************************************************* #include <formatio.h> #include <cvirte.h> #include <userint.h> #include "toolbar.h" #include "tool bar.h" //********************************************************* static int panelHandle,menubarhandle; static ToolbarType calctoolbar,helptoolbar,edittoolbar,filetoolbar; //********************************************************* //自定义函数声明 void gettoolbar(void); void getitemname (int menuItem); int CVICALLBACK controlCB(int toolbar, int toolbarItemIndex, int event, void *callbackData, int eventData1, int eventData2); //********************************************************* 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; menubarhandle = LoadMenuBar (panelHandle, "tool bar.uir", MENUBAR); //装载菜单 gettoolbar (); //装载工具栏 Toolbar_LoadStates ("menustatus.ini", panelHandle, 0);//装载工具栏设置 // 这句话好像没有什么用处 DisplayPanel (panelHandle); RunUserInterface (); DiscardPanel (panelHandle); CloseCVIRTE (); return 0; } //********************************************************* int CVICALLBACK panelCB (int panel, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_CLOSE: { //保存工具栏设置 Toolbar_SaveStates ("menustatus.ini", panelHandle, 0);// 好像没有什么用处 QuitUserInterface (0); break; } } return 0; } //********************************************************* // 菜单项的回调函数 //********************************************************* void CVICALLBACK menuitemCB (int menuBar, int menuItem, void *callbackData, int panel) { switch (menuItem) { case MENUBAR_FILEMENU_FILENEW: { int index; int dimmed; //自定义函数,传递菜单名称menuItem getitemname (menuItem); //通过描述信息获得按钮在工具栏中的位置 Toolbar_GetIndexFromDescription (filetoolbar, "新建", &index); //获得“新建”按钮的Dimmed属性 Toolbar_GetItemAttribute (filetoolbar, index, TOOLBAR_ATTR_DIMMED, &dimmed); //设置“新建”按钮的Dimmed属性 Toolbar_SetItemAttribute (filetoolbar, index, TOOLBAR_ATTR_DIMMED, !dimmed); // “新建”按钮的dim属性取反 // 在此只是练习一下Toolbar_SetItemAttribute的TOOLBAR_ATTR_DIMMED属性用法而已 break; case MENUBAR_FILEMENU_FILEOPEN: getitemname (menuItem); break; case MENUBAR_FILEMENU_FILESAVE: getitemname (menuItem); break; case MENUBAR_FILEMENU_FILEPRINT: getitemname (menuItem); break; case MENUBAR_FILEMENU_FILEEXIT: getitemname (menuItem); break; case MENUBAR_EDITMENU_EDITUNDO: getitemname (menuItem); break; case MENUBAR_EDITMENU_EDITCUT: getitemname (menuItem); break; case MENUBAR_EDITMENU_EDITCOPY: getitemname (menuItem); break; case MENUBAR_EDITMENU_EDITPASTE: getitemname (menuItem); break; case MENUBAR_HELPMENU_HELPTOPIC: getitemname (menuItem); break; case MENUBAR_HELPMENU_HELPABOUT: getitemname (menuItem); break; } } } //********************************************************* //自定义函数,装载工具栏 //********************************************************* void gettoolbar(void) { //新建“文件”工具栏 Toolbar_New (panelHandle, menubarhandle, "文件", 0, 0, 1, 1, &filetoolbar); //插入一个可移动句柄,使工具栏可以拖拽,注意这句话!!!! //结果试验,这句话放在后面几条语句之间也是可以的 Toolbar_InsertItem (filetoolbar, FRONT_OF_LIST, kMoveHandle, 1, "", kMenuCallback, NULL, 0, 0, ""); //插入菜单按钮 Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "新建", kMenuCallback, MENUBAR_FILEMENU_FILENEW, 0, 0, "new.ico"); Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "打开", kMenuCallback, MENUBAR_FILEMENU_FILEOPEN, 0, 0, "open.ico"); Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "保存", kMenuCallback, MENUBAR_FILEMENU_FILESAVE, 0, 0, "save.ico"); Toolbar_InsertItem (filetoolbar, END_OF_LIST, kSeparator, 1, "", kMenuCallback, NULL, 0, 0, ""); Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "打印", kMenuCallback, MENUBAR_FILEMENU_FILEPRINT, 0, 0, "print.ico"); Toolbar_InsertItem (filetoolbar, END_OF_LIST, kSeparator, 1, "", kMenuCallback, NULL, 0, 0, ""); Toolbar_InsertItem (filetoolbar, END_OF_LIST, kCommandButton, 1, "退出", kMenuCallback, MENUBAR_FILEMENU_FILEEXIT, 0, 0, "exit.ico"); //显示工具栏 Toolbar_Display (filetoolbar); //-------------------------------------------------------- Toolbar_New (panelHandle, menubarhandle, "编辑", 0, 0, 1, 1, &edittoolbar); Toolbar_InsertItem (edittoolbar, FRONT_OF_LIST, kMoveHandle, 1, "", kMenuCallback, NULL, 0, 0, ""); Toolbar_InsertItem (edittoolbar, END_OF_LIST, kExclusiveToggleButton, 1, "剪切", kMenuCallback, MENUBAR_EDITMENU_EDITCUT, 0, 0, "cut.ico"); Toolbar_InsertItem (edittoolbar, END_OF_LIST, kExclusiveToggleButton, 1, "复制", kMenuCallback, MENUBAR_EDITMENU_EDITCOPY, 0, 0, "copy.ico"); Toolbar_InsertItem (edittoolbar, END_OF_LIST, kExclusiveToggleButton, 1, "粘贴", kMenuCallback, MENUBAR_EDITMENU_EDITPASTE, 0, 0, "paste.ico"); Toolbar_Display (edittoolbar); //-------------------------------------------------------- Toolbar_New (panelHandle, menubarhandle, "帮助", 0, 0, 1, 1, &helptoolbar); Toolbar_InsertItem (helptoolbar, FRONT_OF_LIST, kMoveHandle, 1, "", kMenuCallback, NULL, 0, 0, ""); Toolbar_InsertItem (helptoolbar, END_OF_LIST, kCommandButton, 1, "关于", kMenuCallback, MENUBAR_HELPMENU_HELPABOUT, 0, 0, "about.ico"); Toolbar_Display (helptoolbar); //-------------------------------------------------------- //新建一个“计数”工具栏,计算“文件”工具栏按钮数目 Toolbar_New (panelHandle, menubarhandle, "计数", 0, 0, 1, 1, &calctoolbar); Toolbar_InsertItem (calctoolbar, FRONT_OF_LIST, kMoveHandle, 1, "", kMenuCallback, NULL, 0, 0, ""); //-------------------------------------------------------- //插入一个按钮,并建立controlCB回调函数 Toolbar_InsertItem (calctoolbar, END_OF_LIST, kCommandButton, 1, "计数", kControlCallback, NULL, controlCB, 0, "toolbox.ico"); Toolbar_Display (calctoolbar); //-------------------------------------------------------- Toolbar_SetAttribute (filetoolbar, TOOLBAR_ATTR_BUTTON_IMAGE_SIZE, 32); Toolbar_SetAttribute (edittoolbar, TOOLBAR_ATTR_BUTTON_IMAGE_SIZE, 32); Toolbar_SetAttribute (helptoolbar, TOOLBAR_ATTR_BUTTON_IMAGE_SIZE, 32); Toolbar_SetAttribute (calctoolbar, TOOLBAR_ATTR_BUTTON_IMAGE_SIZE, 32); } //********************************************************* //自定义函数,将菜单名称传递给String控件 //********************************************************* void getitemname (int menuItem) { char itemname[120]; GetMenuBarAttribute (menubarhandle, menuItem, ATTR_ITEM_NAME, itemname); SetCtrlVal (panelHandle, PANEL_STRING, itemname); } //********************************************************* // 安装工具栏控件的回调函数 //********************************************************* int CVICALLBACK controlCB(int toolbar, int toolbarItemIndex, int event, void *callbackData, int eventData1, int eventData2) { int count; char string1[150]; //得到第一行工具栏,即“文件”工具栏的按钮数目 Toolbar_GetNumItems (filetoolbar, &count); Fmt (string1, "文件工具栏(包含分隔符|)的按钮数目是:%i", count); SetCtrlVal (panelHandle, PANEL_STRING, string1); return 0; } //********************************************************* //********************************************************* //*********************************************************
用户435334 2015-6-16 16:45
用户1756693 2014-5-8 11:51