Dynamic popup menu for tray icon

tasos's Avatar, Join Date: Jan 2009
Newbie Member
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. 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 shabbir; 23Jan2009 at 22:33.. Reason: Code blocks
0
tasos's Avatar, Join Date: Jan 2009
Newbie Member
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Right arrow comes when you have sub menu under that menu item.