1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Dynamic popup menu for tray icon

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

  1. tasos

    tasos New 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:
        // 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)
                    // Load item.
                    archive >> strLoadedBasePopupMenuItem;
                    // Try to find substring "+---".
                    // Item is basePopupMenu.
                    if (strLoadedBasePopupMenuItem.Find(_T("+---")) == -1) 
                        // Create new popup menu.
                        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 (+).
                        basePopupMenu.AppendMenu(MF_ENABLED | MF_POPUP,     (UINT)&m_NewMenu.m_hMenu, strLoadedBasePopupMenuItem);
                while (archive.IsBufferEmpty()==0);
            // Close archive and file.
    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

    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

    Right arrow comes when you have sub menu under that menu item.

Share This Page