在 MFC 中,CWinApp::UnregisterShellFileTypes 方法是用于取消注册应用程序关联文件类型的受保护方法。通常情况下,你可以在你的 CWinApp 派生类的 ExitInstance 函数中调用这个方法,以确保在应用程序关闭时取消注册文件类型。

以下是一个简单的示例:
class CMyApp : public CWinApp
{
public:
    virtual BOOL InitInstance();
    virtual int ExitInstance();
    // 其他成员函数和声明...
};

BOOL CMyApp::InitInstance()
{
    // 其他初始化代码...

    // 注册文件类型
    RegisterShellFileTypes(TRUE);

    // 其他初始化代码...

    return TRUE;
}

int CMyApp::ExitInstance()
{
    // 取消注册文件类型
    UnregisterShellFileTypes();

    // 其他清理代码...

    return CWinApp::ExitInstance();
}

在这个示例中,RegisterShellFileTypes(TRUE) 在应用程序初始化时注册文件类型,而 UnregisterShellFileTypes() 在应用程序退出时取消注册文件类型。这样可以确保应用程序在关闭时清理注册表中的相关信息。

需要注意的是,这个方法在 CWinApp 类中是受保护的,只能在派生类的 ExitInstance 函数中调用。


转载请注明出处:http://www.zyzy.cn/article/detail/23153/MFC/CWinApp