Why isn't the dropdown arrow drawn for an CMFCMenuButton?

不羁岁月 提交于 2019-12-05 13:00:20
bsruth

The reason I posted this question is because I couldn't find any answers via Google. The closest I came when researching it was a couple hacks that didn't seem to be the real solution. After pouring over the NewControls example, I finally found the culprit.

At the bottom of the default .rc file for a project, there is the following code:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#include "res\YOUR_PROJECT_NAME.rc2"  // non-Microsoft Visual C++ edited resources
#include "afxres.rc"      // Standard components
#endif

The NewControls example's .rc file looks like this:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#include "res\NewControls.rc2"  // non-Microsoft Visual C++ edited resources
#include "afxres.rc"      // Standard components
#ifndef _AFXDLL
#include "afxribbon.rc"      // Ribbon and control bars
#endif
#endif

Adding the afxribbon.rc enables the bitmap resources needed for the controls in the MFC Feature pack update. Now you can't just simply add the missing code to the bottom of the .rc file. If you do that, every time you edit the resource file using the visual designer, your added code will be removed. The solution to the problem is to add this to the bottom of the YOUR_PROJECT_NAME.rc2 file:

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

Make sure you have an empty line at the bottom of the file, or the resource compiler will complain. I'm not sure what setting needs to be adjusted in order for the visual designer to automatically include afxribbon.rc like it does in the NewControls example project. But adding it to the .rc2 seems to fix the problem.


Update

Keep in mind that you can use the IDE to modify your RC file:

  • Right-Click the RC file and select Resource Includes...:

  • Paste the new code into the Compile-time directives area:

Paranoik

I solve this problem for myself in such way: I add a clause to CMyApp::InitInstance:

BOOL CMyApp::InitInstance()
{
    CWinAppEx::InitInstance();

    InitCommonControls();

    //This! 
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

    //...
    return TRUE;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!