Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Dynamic popup menu for tray icon (http://www.go4expert.com/forums/dynamic-popup-menu-tray-icon-t15915/)

tasos 23Jan2009 22:25

Dynamic popup menu for tray icon
 
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.

tasos 24Jan2009 18:29

Re: Dynamic popup menu for tray icon
 
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.

shabbir 24Jan2009 18:33

Re: Dynamic popup menu for tray icon
 
Right arrow comes when you have sub menu under that menu item.


All times are GMT +5.5. The time now is 11:15.