⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menudemo.c

📁 labwindow 编程的toolbox例程。
💻 C
📖 第 1 页 / 共 3 页
字号:
    if ((menuListHandle) && (fullPathAndFilename)
        &&  (fullPathAndFilename[0] != '\0') )
        retVal = MU_AddItemToMenuList (menuListHandle, FRONT_OF_LIST,
                                       MU_MakeShortFileName (NULL,
                                                             fullPathAndFilename,
                                                             32),
                                       StrDup (fullPathAndFilename));
    return retVal;   
}       

/*--------------------------------------------------------------------------*/
/* Add a particular window entry to the Window menu's MRU list.             */
/*--------------------------------------------------------------------------*/
static int AddFileNameToWindowMenuList (menuList menuListHandle,
                                        char *fullPathAndFilename,
                                        int panel)
{
    int                    retVal = 0;
    WindowMenuCallbackData *callbackData;
    
    if ((menuListHandle) && (fullPathAndFilename)
        &&  (fullPathAndFilename[0] != '\0')) 
        { 
        if (callbackData = calloc (1, sizeof(WindowMenuCallbackData)))
            {
            strcpy (callbackData->fileName, fullPathAndFilename);
            callbackData->panel = panel;
            retVal = MU_AddItemToMenuList (menuListHandle, FRONT_OF_LIST,
                                           MU_MakeShortFileName (NULL,
                                                                 fullPathAndFilename,
                                                                 32),
                                           callbackData);
            }    
        }        
    return retVal;   
}       

/*---------------------------------------------------------------------------*/
/* Remove a particular file from the File menu's MRU list.                   */
/*---------------------------------------------------------------------------*/
static int RemoveFileNameFromMenuList (menuList menuListHandle,
                                       char *fullPathAndFilename)
{
    int  retVal = 0;
    int  item = 0;
    int  totalItems = 0;
    char *fileName;
    
    /* Find menu item and remove from list */
    if ((menuListHandle) && (fullPathAndFilename)
        &&  (fullPathAndFilename[0] != '\0')) 
        { 
        if (totalItems = MU_GetNumMenuListItems (menuListHandle))
            {
            for (item = 1; item <= totalItems; item++) 
                {
                fileName = 0;
                MU_GetMenuListAttribute (menuListHandle, item,
                                         ATTR_MENULIST_ITEM_CALLBACK_DATA,
                                         &fileName);
                if ((fileName) &&
                    (strcmp (fileName, fullPathAndFilename) == 0))
                    break;
                }    
            if (item <= totalItems)
                MU_DeleteMenuListItem (menuListHandle, item);
            }    
        }        
    return retVal;   
}       

/*---------------------------------------------------------------------------*/
/* Check to see if the file is already in the Window Menu MRU list.          */
/*---------------------------------------------------------------------------*/
static int CheckForFileNameInMenuList (menuList menuListHandle,
                                       char *fullPathAndFilename)
{
    int  retVal = 0;
    int  item = 0;
    int  totalItems = 0;
    char *fileName;
    
    /* Find menu item in list*/
    if ((menuListHandle) && (fullPathAndFilename)
        &&  (fullPathAndFilename[0] != '\0')) 
        { 
        if (totalItems = MU_GetNumMenuListItems (menuListHandle))
            {
            for (item = 1; item <= totalItems; item++) 
                {
                fileName = 0;
                MU_GetMenuListAttribute (menuListHandle, item,
                                         ATTR_MENULIST_ITEM_CALLBACK_DATA,
                                         &fileName);
                if ((fileName) &&
                    (strcmp (fileName, fullPathAndFilename) == 0))
                    retVal = 1;
                }
            }
        }        
    return retVal;   
}       

/*---------------------------------------------------------------------------*/
/* This menu callback function is called when a filename is chosen from the  */
/* MRU list on the File menu.  callbackData will point to the long filename, */
/* since we're just using the short one in the MRU list.                     */
/*---------------------------------------------------------------------------*/
static void CVICALLBACK FILEMenuListCallbackFunc (menuList list, int menuIndex,
                                                  int event,
                                                  void *callbackData)
{
    int  status;
    int  childPanel;
    char *fileName = (char *)callbackData;
   
    if (event == EVENT_DISCARD)
        {
        if (fileName)
            free (fileName);
        }
    else if (fileName) 
        {
        if (!CheckForFileNameInMenuList(g_winMenuListHandle, fileName))
            {
            /* Create a child panel to represent the newly opened file */
            if ((childPanel = LoadPanel (g_panelHandle, "menudemo.uir", FILEPANEL))
                >= 0)
                {
            
                /* Set top and left for child panel */
                SetPanelAttribute (childPanel, ATTR_TOP,
                                   g_topLeftValue * 25 + 50);
                SetPanelAttribute (childPanel, ATTR_LEFT,
                                   g_topLeftValue * 25 + 25);
                g_topLeftValue = (g_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);
                g_numChildPanels++;
            
                /* Add an item for this window to the WINDOW MRU list */
                status = AddFileNameToWindowMenuList (g_winMenuListHandle,
                                                      fileName, childPanel);
                DimMenuItems ();
                }
            else
                {
                sprintf (g_msgBuffer, "Failure in LoadPanel.");
                MessagePopup ("MenuDemo", g_msgBuffer);
                }
            }
        else
            MessagePopup("File Open", "File is already open.  Use Window menu to see list of open files.");
        }   
    return;         
}

/*---------------------------------------------------------------------------*/
/* This menu callback function is called when a filename is chosen in the    */
/* WINDOW menu's MRU list.  callbackData will point to a structure we use    */
/* to keep track of the item data.                                           */
/*---------------------------------------------------------------------------*/
static void CVICALLBACK WINDOWMenuListCallbackFunc (menuList list,
                                                    int menuIndex, int event,
                                                    void *callbackData)
{
    WindowMenuCallbackData *data = callbackData;
   
    if (event == EVENT_DISCARD)
        {
        if (data)
            free(data);
        }
    else
        {
        
        /* Restore the window 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;
}


/*---------------------------------------------------------------------------*/
/* Respond to the File->Open command to open a new file, which in this demo  */
/* basically just creates a child panel for it.                              */
/*---------------------------------------------------------------------------*/
void CVICALLBACK FileOpen (int menuBar, int menuItem, void *callbackData,
                          int panel)
{
    int  stat;
    int  childPanel;
    char fileName[MAX_PATHNAME_LEN];
    
    /* Get fileName from user */    
    stat = FileSelectPopup ("", "*.*", "", "Choose a file to open",
                            VAL_LOAD_BUTTON, 0, 0, 1, 0, fileName);
    if ((stat == VAL_EXISTING_FILE_SELECTED)
        || (stat == VAL_NEW_FILE_SELECTED))
        {
        if (!CheckForFileNameInMenuList(g_winMenuListHandle, fileName))
            {
            /* Create a child panel to represent the newly opened file */
            if ((childPanel = LoadPanel (panel, "menudemo.uir", FILEPANEL))
                >= 0)
                {
            
                /* Set top and left for child panel */
                SetPanelAttribute (childPanel, ATTR_TOP,
                                   g_topLeftValue * 25 + 50);
                SetPanelAttribute (childPanel, ATTR_LEFT,
                                   g_topLeftValue * 25 + 25);
                g_topLeftValue = (g_topLeftValue + 1) % 5;
            
                /* Set Title of child panel */
                SetPanelAttribute (childPanel, ATTR_TITLE,
                                   MU_MakeShortFileName(NULL, fileName, 32));
                SetCtrlVal (childPanel, FILEPANEL_FILENAME, fileName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -