none
CMFCPopupMenu and CMFCVisualManagerOffice2007 - not a good match RRS feed

  • Question

  • Hi.

    I've noticed that if I use the following code:

    CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;

    after issuing this:

    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));

    the "new CMFCPopupMenu" has a delay for ~1.5-2.5 seconds.

    However, it's only the first call to "new CMFCPopupMenu" that stalls - calling it again has no delay at all.

    This code:

    printf("%d D\n", GetTickCount());
    CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
    printf("%d E\n", GetTickCount());

    prints out:

    300614160 D

    300615315 E

    If I change the CMFCVisualManagerOffice2007 to CMFCVisualManagerOffice2003 - it works without any delay at all.

    So, anyone has any ideas on why this delay occurs when I use the Office2007 theme? Can't seem to find why it stalls :/

    Thanks in advance.

    Best regards,

    Anton.

    Monday, June 17, 2013 12:52 PM

Answers

  • Hi Anton,

    As per the devs this behavior is by design. The delay is mainly because of some XML parsing being done to load the office colors. The color details are stored in an XML resource file.

    Nibu


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Monday, July 1, 2013 2:18 PM
    Moderator

All replies

  • If you have a repro I can check this out by tomorrow. By the way are you seeing this delay while debugging (with a debugger attached)?

    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Monday, June 17, 2013 3:01 PM
    Moderator
  • Hi Nibu,

    Thank you for your response.

    I don't know where to upload the repro (I made an entirely new MFC-project that has the bug), so I put it on my FTP: http://lindgren.tk/TestMFC.rar

    The changes that I've done to the project:

    In TestMFC.rc2 I added:

    #ifndef _AFXDLL
    #include "afxribbon.rc"      // Ribbon and control bars
    #endif

    In TestMFCDlg.cpp

    ON_COMMAND(IDC_BUTTON1, OnClick)

    And in TestMFCDlg.h

    void OnClick() {
    	int x = GetTickCount();
    	SetDlgItemText(IDC_TEXT, L"You clicked me!");
    
    	// This will stall, or atleast for me..
    	CMFCPopupMenu *pop = new CMFCPopupMenu;
    
    	wchar_t tmp[128] = _T("");
    	_snwprintf_s(tmp, sizeof(tmp)/sizeof(wchar_t), _T("Function took %d ms"), (GetTickCount()-x));
    
    	SetDlgItemTextW(IDC_TEXT2, tmp);
    }

    And this at the InitInstance at TestMFC.cpp

    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // Set this to include all the common control classes you want to use
    // in your application.
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);
    
    InitContextMenuManager();
    InitShellManager();
    InitKeyboardManager();
    InitTooltipManager();
    CMFCToolTipInfo ttParams;
    ttParams.m_bVislManagerTheme = TRUE;
    theApp.GetTooltipManager()->
    SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
    RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
    
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));

    However, there's no doubt in my mind that you'll understand the mess I have made.

    Hopefully, you can enlighten me on why it takes ~1-2 seconds for the first PopupMenu to be created.

    OnTopic: It's the same delay even if I compile it as "Release" and run it. :/

    Best regards,

    Anton.


    • Edited by AntonLindgren Tuesday, June 18, 2013 12:22 PM Fixed a typo
    Monday, June 17, 2013 4:07 PM
  • Sorry Anton,

    I've been out of office for couple of days now, kids were not well. Checking this out now, in debug for me its showing time taken as 328 ms, while in release its showing 187 ms.

    Checking this out further. Will keep you posted.


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.


    Wednesday, June 19, 2013 8:38 AM
    Moderator
  • Hi,

    Thanks for your reply.

    When I run the .exe I compiled in debug (also in the .rar), it takes about 1000ms the first time, then 0ms.

    I'm using Visual Studio 2010, SP1Rel. I've tried running it on different machines (Win7 64-bit and XP) - same delay.

    For now, the solution I'm using for my software is:

    CMFCPopupMenu *c = new CMFCPopupMenu;
    delete c;
    

    at my InitInstante(), right under:

    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));

    It works (giving a small 1sec delay on showing the window, but my rightclick at systray takes 0-16ms), but pref. I'd like to know why it stalls the first time - and why only on ManagerOffice2007. :/

    Thank you for your time, and effort. I appreciate it.

    Best regards,

    Anton.

    Wednesday, June 19, 2013 11:38 AM
  • Any success? :<

    I've tried to run the code in a debugger to see where it delays, but I can't find it. Close to giving up soon :(

    //Anton

    Wednesday, June 26, 2013 7:37 AM
  • Hi,
    Welcome back.
    I will involve more experts to investigate it. It may be some times delayed.
    If you are urgent about this issue, please call the paid Microsoft Support.
    Have a nice day.
    Regards,


    Elegentin Xie
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 26, 2013 9:34 AM
    Moderator
  • Hi Anton,

    I've forwarded the request to devs. Ran profiler with the application and I've shared the logs with them. Awaiting their response.

    Thanks,
    Nibu


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Wednesday, June 26, 2013 10:50 AM
    Moderator
  • Hi Anton,

    As per the devs this behavior is by design. The delay is mainly because of some XML parsing being done to load the office colors. The color details are stored in an XML resource file.

    Nibu


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Monday, July 1, 2013 2:18 PM
    Moderator
  • Hi Nibu Thomas.

    Okaj, so there's nothing I can actually do to decrease this delay? Then I'm gonna use my solution - by allocing a CMFCPopupMenu directly at the start, and freeing it instantly.

    Thank you for your response, and your time. I really appreciate it!

    //Anton

    Monday, July 1, 2013 2:24 PM
  • Hi Anton,

    Instead of instantiating CMFCPopupMenu, call...

    CMFCVisualManager::GetInstance();

    at the start of the program (yes it looks weird :) but will look better than creating a temporary CMFCPopupMenu object). Add a line of comment as well.

    Something like...

    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
    // Initialize colors for office 2007 color theme
    CMFCVisualManager::GetInstance();

    Nibu


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.


    Monday, July 1, 2013 3:18 PM
    Moderator