我用VC写了一个简单的自动化组件嵌在网页内,但每次浏览该网页总是出现以下提示信息:   “在此页上的ActiveX控件可能和本页上的其它部件的交流不安全,你想允许这种交流吗?”请问大虾该如何解决?? 解决后保证给分!!

解决方案 »

  1.   

    要实现两个接口,初始化安全化接口和脚本安全话接口!如果用ATL则加入:BEGIN_CATEGORY_MAP(CMyControl)
        IMPLEMENTED_CATEGORY(CATID_SafeForInitializing)
        IMPLEMENTED_CATEGORY(CATID_SafeForScripting)
    END_CATEGORY_MAP()MFC要改哪个UPDATEREISTERUpdateRegistry(BOOL bRegister)
    { if (bRegister)
    {
    BOOL retval = AfxOleRegisterControlClass(
    AfxGetInstanceHandle(),
    m_clsid,
    m_lpszProgID,
    IDS_MADMETHODCALL,
    IDB_MADMETHODCALL,
    afxRegApartmentThreading,
    _dwMadMethodCallOleMisc,
    _tlid,
    _wVerMajor,
    _wVerMinor);
    //  as safe for scripting--failure OK
    HRESULT hr = CreateComponentCategory(CATID_SafeForScripting, 
    L"Controls that are safely scriptable"); if (SUCCEEDED(hr))
    // only register if category exists
    RegisterCLSIDInCategory(m_clsid, CATID_SafeForScripting);
    // don't care if this call fails //  as safe for data initialization
    hr = CreateComponentCategory(CATID_SafeForInitializing, 
    L"Controls safely initializable from persistent data"); if (SUCCEEDED(hr))
    // only register if category exists
    RegisterCLSIDInCategory(m_clsid, CATID_SafeForInitializing);
    // don't care if this call fails return retval;
    }
    else
    {
    return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
    }
    }
    HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
    {    ICatRegister* pcr = NULL ; // interface pointer
        HRESULT hr = S_OK ;    hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
    NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
    if (FAILED(hr))
    return hr;    // Make sure the HKCR\Component Categories\{..catid...}
        // key is registered
        CATEGORYINFO catinfo;
        catinfo.catid = catid;
        catinfo.lcid = 0x0409 ; // english // Make sure the provided description is not too long.
    // Only copy the first 127 characters if it is
    int len = wcslen(catDescription);
    if (len>127)
    len = 127;
        wcsncpy(catinfo.szDescription, catDescription, len);
    // Make sure the description is null terminated
    catinfo.szDescription[len] = '\0';    hr = pcr->RegisterCategories(1, &catinfo);
    pcr->Release(); return hr;
    }
    HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
    {
    // Register your component categories information.
        ICatRegister* pcr = NULL ;
        HRESULT hr = S_OK ;
        hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, 
    NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
        if (SUCCEEDED(hr))
        {
           // Register this category as being "implemented" by
           // the class.
           CATID rgcatid[1] ;
           rgcatid[0] = catid;
           hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid);
        }    if (pcr != NULL)
            pcr->Release();
      
    return hr;
    }