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

📄 menudemo.c

📁 labwindow 编程的toolbox例程。
💻 C
📖 第 1 页 / 共 3 页
字号:
            
                /* Display the child panel */
                DisplayPanel (childPanel);
                g_numChildPanels++;
            
                /* Add a menu item to the WINDOW list for this opened window */
                AddFileNameToWindowMenuList (g_winMenuListHandle, fileName,
                                             childPanel);
    
                DimMenuItems ();
                sprintf (g_msgBuffer, "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 (g_msgBuffer, "Failure to LoadPanel.");
            MessagePopup("Menu Utility Demo",g_msgBuffer);
            }
        else
            MessagePopup("File Open", "File is already open.  Use Window menu to see list of open files.");
        }
}

/*----------------------------------------------------------------------------*/
/* Respond to the File->Save As menu item to save a currently open file, which*/
/* includes adding it to the FILE menu's MRU list.                            */
/*----------------------------------------------------------------------------*/
void CVICALLBACK FileSaveAs (int menuBar, int menuItem, void *callbackData,
                             int panel)
{
    int  stat;
    int  childPanel;
    char fileName[MAX_PATHNAME_LEN];
    char oldFileName[MAX_PATHNAME_LEN];
        
    childPanel = GetTopChildWindow (panel);    
    if ((childPanel != 0)
        && (GetCtrlVal (childPanel, FILEPANEL_FILENAME, oldFileName) == 0))
        {
        stat = FileSelectPopup ("", "*.*", "", "Choose a filename to save as:",
                                VAL_SAVE_BUTTON, 0, 0, 1, 0, fileName);
                              
        if ((stat == VAL_EXISTING_FILE_SELECTED)
            || (stat == VAL_NEW_FILE_SELECTED))
            {
            
            /* Add menu item to FILE list */
            AddFileNameToFileMenuList (g_fileMenuListHandle, oldFileName);
            
            /* Remove old menu item from WINDOW list */
            RemoveFileNameFromMenuList (g_winMenuListHandle, oldFileName);
            
            /* Add menu item to WINDOW list */
            SetPanelAttribute (childPanel, ATTR_TITLE,
                               MU_MakeShortFileName(NULL, fileName, 32));
            SetCtrlVal (childPanel, FILEPANEL_FILENAME, fileName);
            AddFileNameToWindowMenuList (g_winMenuListHandle, fileName,
                                         childPanel);
            DimMenuItems ();
            sprintf (g_msgBuffer, "The following file will be saved:"
                                  "\n  %s\n\nThe old filename will be added "
                                  "to the 'File' menu's MRU list\n\n"
                                  "NOTE:  The actual file will not be modified.", fileName);
            MessagePopup ("MenuDemo", g_msgBuffer);
            }    
        }    
}

/*---------------------------------------------------------------------------*/
/* Respond to the File->Save menu option to save the currently open file.    */
/* This includes adding it to the File menu's MRU list.                      */
/*---------------------------------------------------------------------------*/
void CVICALLBACK FileSave (int menuBar, int menuItem, void *callbackData,
                           int panel)
{
    int  childPanel;
    char fileName[MAX_PATHNAME_LEN];
        
    childPanel = GetTopChildWindow (panel);    
    if ((childPanel != 0)
        && (GetCtrlVal (childPanel, FILEPANEL_FILENAME, fileName) == 0))
        {
        /* Add menu item to FILE list */
        AddFileNameToFileMenuList (g_fileMenuListHandle, fileName);
        sprintf (g_msgBuffer, "The following file was selected to be saved:\n"
                              " %s\n\nNOTE: Actual file will not be modified.",
                              fileName);
        MessagePopup ("MenuDemo",g_msgBuffer);
        }                            
}

/*----------------------------------------------------------------------------*/
/* Get the topmost child panel for a given parent.                            */
/*----------------------------------------------------------------------------*/
static 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;
}

/*----------------------------------------------------------------------------*/
/* Respond to File->Close menu item to close a file and add it to the MRU list*/                                                                  
/*----------------------------------------------------------------------------*/
void CVICALLBACK FileClose (int menuBar, int menuItem, void *callbackData,
                            int panel)
{
    char fileName[MAX_PATHNAME_LEN];
    
    if ((panel = GetTopChildWindow(panel)) >= 0)
        {    
        GetCtrlVal (panel, FILEPANEL_FILENAME, fileName);
        DiscardPanel (panel);
        AddFileNameToFileMenuList (g_fileMenuListHandle, fileName);
        RemoveFileNameFromMenuList (g_winMenuListHandle, fileName);
        g_numChildPanels--;
        DimMenuItems ();
        }    
}

/*---------------------------------------------------------------------------*/
/* Respond to File->Exit menu item to close the app.  We must add currently  */
/* open files to the File menu's MRU list, and remove items from the Window  */
/* menu's MRU list.                                                          */
/*---------------------------------------------------------------------------*/
void CVICALLBACK FileQuit (int menuBar, int menuItem, void *callbackData,
                           int panel)
{
    char *fileName;
    
    if (g_numChildPanels)
        {
        while ((MU_GetMenuListAttribute (g_winMenuListHandle, 1,
                                         ATTR_MENULIST_ITEM_CALLBACK_DATA,
                                         &fileName) == 0))
            {
            AddFileNameToFileMenuList (g_fileMenuListHandle, fileName);
            RemoveFileNameFromMenuList (g_winMenuListHandle, fileName);
            }
        sprintf (g_msgBuffer, "You are now exiting, any open files will be "
                              "saved in the File list");
        MessagePopup("MenuDemo", g_msgBuffer);
        g_numChildPanels = 0;
        DimMenuItems ();
    }    
    QuitUserInterface (0);
}

/*--------------------------------------------------------------------------*/
/* Hide all of the currently open child windows.                            */
/*--------------------------------------------------------------------------*/
void CVICALLBACK HideAllWindows (int menuBar, int menuItem,
                                 void *callbackData, int panel)
{
    int childPanels = 0;
    int childPanelHandle;
    int i;
        
    GetPanelAttribute (panel, ATTR_NUM_CHILDREN, &childPanels);
    for (i = 0; i < childPanels; i++)
        {
        if (i == 0)
            GetPanelAttribute (panel, ATTR_FIRST_CHILD, &childPanelHandle);
        else 
            GetPanelAttribute (childPanelHandle, ATTR_NEXT_PANEL, &childPanelHandle);
        if (childPanelHandle)
            SetPanelAttribute (childPanelHandle, ATTR_VISIBLE, 0);
        }    
}

/*--------------------------------------------------------------------------*/
/* Close all of the currently open windows.                                 */
/*--------------------------------------------------------------------------*/
void CVICALLBACK CloseAllWindows (int menuBar, int menuItem,
                                  void *callbackData, int panel)
{
    int  childPanels = 0;
    int  i;
    int  childPanel;
    char fileName[MAX_PATHNAME_LEN];
    
    GetPanelAttribute (panel, ATTR_NUM_CHILDREN, &childPanels);
    for (i = 0; i < childPanels; i++) 
        {
        childPanel = GetTopChildWindow (panel);    
        GetCtrlVal (childPanel, FILEPANEL_FILENAME, fileName);
        AddFileNameToFileMenuList (g_fileMenuListHandle, fileName);
        RemoveFileNameFromMenuList (g_winMenuListHandle, fileName);
        DiscardPanel (childPanel);
        g_numChildPanels--;
        }    
    DimMenuItems ();
}

/*----------------------------------------------------------------------------*/
/* Help                                                                       */
/*----------------------------------------------------------------------------*/
void CVICALLBACK Help (int menubar, int menuItem, void *callbackData, int panel)
{
    MessagePopup ("MenuDemo","This demo illustrates the use of the Menu Util\n"
                             "Instrument Driver to implement MRU lists on CVI"
                             "\nmenus.  See the source file and FP for more "
                             "information.");
}



⌨️ 快捷键说明

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