views:

35

answers:

1

I'm trying to create context menu using TrackPopupMenu function in my application, the code I use in it is like the following:

CMenu menu;
        if (menu.LoadMenu(IDR_MENU_TRAY))
        {
            CMenu* pSubMenu = menu.GetSubMenu(0);
            if (pSubMenu != NULL)
            {
                pSubMenu->ModifyMenu(IDM_CLOSE,MF_BYCOMMAND,IDM_CLOSE ,g_cfg->GetLang(TEXT_MAIN_CLOSE,"Exit(&X)")); 
                pSubMenu->ModifyMenu(IDM_SHOW,MF_BYCOMMAND,IDM_SHOW ,g_cfg->GetLang(TEXT_MAIN_OPEN_SHUTTER,"Open(&O)"));
                CPoint point;
                GetCursorPos(&point);                                                                   
                SetForegroundWindow();  
                pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, messageOnlyWnd); 
            }
        }

The code runs perfect on WinXP, while on win7 and vista it doesn't. The Problem on win7 and vista is that it takes a fairly long time to pop up the menu, maybe 1 min or more. But if I turn off the Aero on win7 or vista, it runs smoothly just like on winXP, so I guess somethin must be conflicted with Aero in the code, but I just don't know how to fix it. Is there anyone can help me with that? I will appreciate it a lot if anybody helps me out.

A: 

I don't see anything wrong with this code. I've used TrackPopupMenu on Vista without any problems. The source of the problem might lie elsewhere. Try removing the call to SetForegroundWindow. If that doesn't work, try creating an empty project with just the popup menu code.

casablanca
Thanks for your answer. I tried as you suggested, but the problem is still there. Creating an empty project with just the popup menu code works smoothly on win7 with Aero on. In my application, even poping up a menu when right click in a CEdit control takes quite a long time for the menu to show. But when the Aero is turned off, everything's OK.Besides I didn't use any other libs or code except the TrackPopupMenu function when creating a pop up menu, so I'm confused with it for quite a long time. It drives me crazy!!
AJAY
It's difficult to diagnose any further without looking at the rest of your code. Is your application doing any background processing in the main thread? This could slow down the GUI.
casablanca
It does do some background processing, but what I cannot understand is that it can run smoothly on WinXP and Win7 with Aero turned off but not on Win7 with Aero on when creating a pop up menu. So I guess there may be something conflicted between the Aero in Win7 and the function TrackPopupMenu. I also set some breakpoints in my code using VS2003, found that other lines runs smoothly except the line with TrackPopupMenu, which takes as long as 1min to finish!
AJAY
What kind of background processing? I suggest you move that code into a separate thread.
casablanca
Something like socket communication, and it does run in a separate thread, so I don't think it's the part that matters. What I think most likely is that there are some conflicts between the Aero in Win7 and the function TrackPopupMenu which I cannot figure out. PS:I also use GDI+ and DirectShow libs in my application, but I didn't use them to render a pop up menu. Only MFC functions such as TrackPopupMenu are used to create the menu.
AJAY