1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Dynamic popup menu for tray icon

Discussion in 'MFC' started by tasos, Jan 23, 2009.

  1. tasos

    tasos New Member

    Joined:
    Jan 23, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello to everyone,

    This is my first post ever in this forum. The problem I came across is about a popup menu in Visual C++.

    The application creates a tray icon. Now, I create a menu (baseMenu) with the resource editor of Visual Studio (2008). Then, baseMenu is successfully loaded and I am able to see it when I click to the tray icon. So far so good...

    However, I want the application to be able to add new popup menus to baseMenu during runtime. Until now, I can only add new items (basePopupMenus) with AppendMenu(). But, I have a problem populating basePopupMenus with new items before adding them to baseMenu.

    Here is the code I use so far:
    Code:
    baseMenu.LoadMenu(IDR_BASE_MENU);
    
        // Open file to read new items from.
        CFile m_fileItems;
    
        if (m_fileItems.Open(_T("items.it"), CFile::modeRead))
        {
            // Open archive.
            CArchive archive(&m_fileItems, CArchive::load);
            CString strLoadedBasePopupMenuItem;
        
            // If file is not empty.
            if (m_fileItems.GetLength() != 0)
            {
                do
                {            
                    // Load item.
                    archive >> strLoadedBasePopupMenuItem;
    
                    // Try to find substring "+---".
                    // Item is basePopupMenu.
                    if (strLoadedBasePopupMenuItem.Find(_T("+---")) == -1) 
                    {
                        // Create new popup menu.
                        basePopupMenu.CreatePopupMenu();  
                        baseMenu.GetSubMenu(0)->AppendMenu(MF_ENABLED | MF_POPUP, (UINT)&basePopupMenu.m_hMenu, strLoadedBasePopupMenuItem);
                    }
                    else // Item is application.
                    {    
                        strLoadedBasePopupMenuItem.Remove('-'); // Removing dashes (-)
                        strLoadedBasePopupMenuItem.Remove('+'); // and plus sign (+).
                            
                        basePopupMenuItem.CreatePopupMenu();
                        basePopupMenu.AppendMenu(MF_ENABLED | MF_POPUP,     (UINT)&m_NewMenu.m_hMenu, strLoadedBasePopupMenuItem);
                    }
                }
                while (archive.IsBufferEmpty()==0);
            }
        
            // Close archive and file.
            archive.Close();
            m_fileItems.Close();
    
    I don't know what I am doing wrong here.:crazy: Can anyone, please, tell me what to do?


    Thanks a lot!

    P.S.: Ask me if there is anything I haven't explained enough.
     
    Last edited by a moderator: Jan 23, 2009
  2. tasos

    tasos New Member

    Joined:
    Jan 23, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Sorry if I was a little confusing with my post, above. Allow me to rephrase my problem.

    I have a tray icon and attached a menu to it. What I want is every item in this menu to have a right pointing arrow next to it so as, when I lay the mouse on it, a new menu to appear.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Right arrow comes when you have sub menu under that menu item.
     

Share This Page