📄 menudemo.c
字号:
topLeftValue = (topLeftValue + 1)%5; /* Set Title of child panel */ SetPanelAttribute(childPanel, ATTR_TITLE, MU_MakeShortFileName(NULL, fileName, 32)); SetCtrlVal(childPanel, FILEPANEL_FILENAME, fileName); /* Display child panel */ DisplayPanel(childPanel); numChildPanels++; /* Add menu item to WINDOW list */ status = AddFileNameToWindowMenuList(sWindowMenuListHandle, fileName, childPanel); DimMenuItems(); /* sprintf(sMsgBuffer, "You selected to 'open' the following file:\n %s\n\nNow save or close the file to add it to the 'File' menu.", fileName); */ /* MessagePopup("Menu Utility Demo",sMsgBuffer); */ } else { sprintf(sMsgBuffer, "Failure to LoadPanel."); MessagePopup("Menu Utility Demo",sMsgBuffer); } } return; }/*--------------------------------------------------------------------------*//* WINDOWMenuListCallbackFunc() *//* *//* Parameters: Standard Menu Callback parameters *//* Note: "callbackData" will be pointer to *//* the long filename chosen by user *//* Return: none *//* Purpose: This menu callback function is called *//* when a filename is chosen in the list of *//* files in the FILE menu item *//*--------------------------------------------------------------------------*/static void CVICALLBACK WINDOWMenuListCallbackFunc (menuList list, int menuIndex, int event, void *callbackData){ int status; tWindowMenuCallbackData *data = callbackData; if (event == EVENT_DISCARD) { if (data) free(data); } else { /*----------------------------------------------*/ /* Restore and bring to focus */ /*----------------------------------------------*/ if (data) { DisplayPanel(data->panel); } } return; }/*--------------------------------------------------------------------------*//* MainPanelCallback *//*--------------------------------------------------------------------------*/int CVICALLBACK MainPanelCallback (int panel, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_CLOSE: FileQuit (0, 0, NULL, panel); break; } return 0;}/*----------------------------------------------------------------------------*//* FileOpen *//*----------------------------------------------------------------------------*/void CVICALLBACK FileOpen (int menuBar, int menuItem, void *callbackData, int panel){ int status; char fileName[MAX_PATHNAME_LEN]; int childPanel; /* Get fileName from user */ status = FileSelectPopup ("", "*.*", "", "Choose a file to open", VAL_LOAD_BUTTON, 0, 0, 1, 0, fileName); if ((status == VAL_EXISTING_FILE_SELECTED) || (status == VAL_NEW_FILE_SELECTED)) { /* Create a child panel to represent the newly opened file */ if ((childPanel = LoadPanel (panelHandle, "menudemo.uir", FILEPANEL)) >= 0) { /* Set top and left for child panel */ SetPanelAttribute(childPanel, ATTR_TOP, topLeftValue*25+50); SetPanelAttribute(childPanel, ATTR_LEFT, topLeftValue*25+25); topLeftValue = (topLeftValue + 1)%5; /* Set Title of child panel */ SetPanelAttribute(childPanel, ATTR_TITLE, MU_MakeShortFileName(NULL, fileName, 32)); SetCtrlVal(childPanel, FILEPANEL_FILENAME, fileName); /* Display child panel */ DisplayPanel(childPanel); numChildPanels++; /* Add menu item to WINDOW list */ status = AddFileNameToWindowMenuList(sWindowMenuListHandle, fileName, childPanel); DimMenuItems(); sprintf(sMsgBuffer, "You selected to 'open' the following file:\n %s\n\nNow save or close the file to add it to the 'File' menu.", fileName); } else sprintf(sMsgBuffer, "Failure to LoadPanel."); MessagePopup("Menu Utility Demo",sMsgBuffer); }}/*----------------------------------------------------------------------------*//* FileSaveAs *//*----------------------------------------------------------------------------*/void CVICALLBACK FileSaveAs (int menuBar, int menuItem, void *callbackData, int panel){ int status; int childPanel; char fileName[MAX_PATHNAME_LEN]; char oldFileName[MAX_PATHNAME_LEN]; childPanel = GetTopChildWindow(panelHandle); if ((childPanel!=0) && (GetCtrlVal(childPanel, FILEPANEL_FILENAME, oldFileName)==0)); { status = FileSelectPopup ("", "*.*", "", "Choose a filename to save as", VAL_SAVE_BUTTON, 0, 0, 1, 0, fileName); if ((status == VAL_EXISTING_FILE_SELECTED) || (status == VAL_NEW_FILE_SELECTED)) { /* Add menu item to FILE list */ status = AddFileNameToFileMenuList(sFileMenuListHandle, oldFileName); /* Remove old menu item from WINDOW list */ status = RemoveFileNameFromMenuList(sWindowMenuListHandle, oldFileName); /* Add menu item to WINDOW list */ SetPanelAttribute(childPanel, ATTR_TITLE, MU_MakeShortFileName(NULL, fileName, 32)); SetCtrlVal(childPanel, FILEPANEL_FILENAME, fileName); status = AddFileNameToWindowMenuList(sWindowMenuListHandle, fileName, childPanel); DimMenuItems(); sprintf(sMsgBuffer, "The following file was selected to be saved:\n %s\n\nThe old filename is added to 'File' menu List", fileName); MessagePopup("Menu Utility Demo", sMsgBuffer); } } }/*----------------------------------------------------------------------------*//* FileSave *//*----------------------------------------------------------------------------*/void CVICALLBACK FileSave (int menuBar, int menuItem, void *callbackData, int panel){ int status; char fileName[MAX_PATHNAME_LEN]; int childPanel; childPanel = GetTopChildWindow(panelHandle); if ((childPanel!=0) && (GetCtrlVal(childPanel, FILEPANEL_FILENAME, fileName)==0)); { sprintf(sMsgBuffer, "The following file was selected to be saved:\n %s\n", fileName); MessagePopup("Menu Utility Demo",sMsgBuffer); }}/*----------------------------------------------------------------------------*//* GetTopChildWindow *//*----------------------------------------------------------------------------*/int GetTopChildWindow(int panelHandle){ int i; int panel; int childPanels = 0; int lowZPlane, lowPanel, zPlane; GetPanelAttribute (panelHandle, ATTR_NUM_CHILDREN, &childPanels); /* Find lowest ZPLANE child window */ for (i=0;i<childPanels;i++) { if (i==0) { GetPanelAttribute (panelHandle, ATTR_FIRST_CHILD, &panel); GetPanelAttribute (panel, ATTR_ZPLANE_POSITION, &zPlane); lowZPlane = zPlane; lowPanel = panel; } else { GetPanelAttribute (panel, ATTR_NEXT_PANEL, &panel); if (panel) { GetPanelAttribute (panel, ATTR_ZPLANE_POSITION, &zPlane); if (zPlane<lowZPlane) { lowZPlane = zPlane; lowPanel = panel; } } } } if (childPanels) return lowPanel; else return -1;}/*----------------------------------------------------------------------------*//* FileClose *//*----------------------------------------------------------------------------*/void CVICALLBACK FileClose (int menuBar, int menuItem, void *callbackData, int panel){ int status; char fileName[MAX_PATHNAME_LEN]; if ((panel = GetTopChildWindow(panelHandle))>=0) { GetCtrlVal(panel, FILEPANEL_FILENAME, fileName); DiscardPanel(panel); status = AddFileNameToFileMenuList(sFileMenuListHandle, fileName); status = RemoveFileNameFromMenuList(sWindowMenuListHandle, fileName); /* sprintf(sMsgBuffer, "The following file was closed:\n %s\n\nThe filename is added to 'File' menu List", fileName); */ /* MessagePopup("Menu Utility Demo",sMsgBuffer); */ numChildPanels--; DimMenuItems(); } }/*----------------------------------------------------------------------------*//* FileQuit *//*----------------------------------------------------------------------------*/void CVICALLBACK FileQuit (int menuBar, int menuItem, void *callbackData, int panel){ int status; char *fileName; if (numChildPanels) { while ((MU_GetMenuListAttribute (sWindowMenuListHandle, 1, ATTR_MENULIST_ITEM_CALLBACK_DATA, &fileName)==0)) { status = AddFileNameToFileMenuList(sFileMenuListHandle, fileName); status = RemoveFileNameFromMenuList(sWindowMenuListHandle, fileName); } sprintf(sMsgBuffer, "You are now exiting, any open files will be saved in the File list"); MessagePopup("Menu Utility Demo",sMsgBuffer); numChildPanels = 0; DimMenuItems(); } QuitUserInterface (0);}/*----------------------------------------------------------------------------*//* Help *//*----------------------------------------------------------------------------*/void CVICALLBACK Help(int menubar, int menuItem, void *callbackData, int panel){ MessagePopup ("MENUUTIL Demo",HELP_MSG);}/*--------------------------------------------------------------------------*//* HideAllWindows *//*--------------------------------------------------------------------------*/void CVICALLBACK HideAllWindows (int menuBar, int menuItem, void *callbackData, int panel){ int childPanels = 0; int i; GetPanelAttribute (panelHandle, ATTR_NUM_CHILDREN, &childPanels); for (i=0;i<childPanels;i++) { if (i==0) GetPanelAttribute (panelHandle, ATTR_FIRST_CHILD, &panel); else GetPanelAttribute (panel, ATTR_NEXT_PANEL, &panel); if (panel) SetPanelAttribute (panel, ATTR_VISIBLE, 0); } }/*--------------------------------------------------------------------------*//* CloseAllWindows *//*--------------------------------------------------------------------------*/void CVICALLBACK CloseAllWindows (int menuBar, int menuItem, void *callbackData, int panel){ int childPanels = 0; int i; int status; char fileName[MAX_PATHNAME_LEN]; int childPanel; GetPanelAttribute (panelHandle, ATTR_NUM_CHILDREN, &childPanels); for (i=0;i<childPanels;i++) { childPanel = GetTopChildWindow(panelHandle); GetCtrlVal(childPanel, FILEPANEL_FILENAME, fileName); status = AddFileNameToFileMenuList(sFileMenuListHandle, fileName); status = RemoveFileNameFromMenuList(sWindowMenuListHandle, fileName); DiscardPanel(childPanel); numChildPanels--; } DimMenuItems();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -