简体   繁体   English

从Satellite DLL加载“特殊” MFC控件

[英]Loading a “special” MFC control from a Satellite DLL

I have an MFC application using satellites DLLs in order to support the multilingualism. 我有一个使用附属DLL的MFC应用程序,以支持多种语言。 I am using Visual Studio 2010. 我正在使用Visual Studio 2010。

I am able to change the language of the core part of the application without any problems. 我可以毫无问题地更改应用程序核心部分的语言。 Things go wrong when I try to load a modeless dialog containing a "special" MFC control ( CMFCColorButton , CVSListBox , etc). 当我尝试加载包含“特殊” MFC控件( CMFCColorButtonCVSListBox等)的无模式对话框时,事情出了问题。

The problem occurs at the following statement : 在以下语句中出现问题:

m_dlg->Create(SOME_IID, this); // returns false

How should I proceed to load a "special" MFC control from a satellite DLL? 如何从卫星DLL加载“特殊” MFC控件?

You must register their classes before you reach OnCreate() . 您必须先注册他们的课程,然后才能到达OnCreate() For custom controls, this is typically done in the constructor: 对于自定义控件,通常是在构造函数中完成的:

CMyClass::CMyClass()
{
    // Pseudo code
    m_mfcColorButton.RegisterWindowClass(AfxGetResourceHandle());
}

For MFC controls, I bet there is an initialization function that needs to be called. 对于MFC控件,我敢打赌需要调用一个初始化函数。

I had the same problem: my CDialog - derived class failed in DoModal if I use localized resource dll. 我有同样的问题:如果我使用本地化的资源dll,我的CDialog-派生类在DoModal中将失败。 It contains CMFCColorButton on resource template. 它在资源模板上包含CMFCColorButton。

My solution was to call in a resource dll AfxRegisterMFCCtrlClasses(); 我的解决方案是调用资源dll AfxRegisterMFCCtrlClasses();

class CMyApp: public CWinApp
{
    BOOL InitInstance()
    {
        AfxRegisterMFCCtrlClasses();
        return CWinApp::InitInstance();
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM