據說可以將Activex控件在IE中不顯示安全提示,先收藏,有空再驗證。
轉csdn網友shepherds()
我用的是這種方法:
在classview下,向目錄的第一個.h文件(即App啓動頭文件)中加入以下內容:
//創建Component Categories中的初始化安全和腳本安全項
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription);
//在CLSID中創建與Component Categories中初始化安全和腳本安全項中相對應的implemented Categories項
HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
//註銷與CLSID中的相應implemented Categories項,一般用不到,因爲其它程序可能也會用到這此項
HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid);
extern const GUID CDECL _tlid;
extern const GUID CDECL CLSID_SafeItem;
extern const WORD _wVerMajor;
extern const WORD _wVerMinor;
在對就的.cpp文件中加入以下內容,如果原來程序中已經有的,只改動其中的多餘部分即可:
//設置控件與註冊表相關的類型庫ID,後面跟有version(1.0)字樣,從本工程的.idl文件中獲取
const GUID CDECL BASED_CODE _tlid =
{ 0xB926A326, 0xBE91, 0x4337, { 0xA1, 0xDC, 0x76, 0x1B, 0x73, 0x15, 0x6B, 0x23 } };
//控件在註冊表中的CLSID,後面跟有control字樣,從本工程的.idl文件中獲取
const GUID CDECL CLSID_SafeItem =
{ 0xAF546E3F, 0xB5B8, 0x42D6, {0xBB, 0x74, 0x84, 0xB7, 0x25, 0xC0, 0x38, 0x4D}};
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
STDAPI DllRegisterServer(void)
{
HRESULT hr;
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(TRUE))
return ResultFromScode(SELFREG_E_CLASS);
//創建腳本安全“補充”項,非CLSID中
hr = CreateComponentCategory(CATID_SafeForScripting, L"Controls safely scriptable!");
if (FAILED(hr))
return hr;
//創建初始化安全“補充”項,非CLSID中
hr = CreateComponentCategory(CATID_SafeForInitializing, L"Controls safely initializable from persistent data!");
if (FAILED(hr))
return hr;
//設置控件CLSID中補充項的腳本安全項,與“補充”項中的腳本安全項對應
hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
if (FAILED(hr))
return hr;
//設置控件CLSID中補充項的初始化安全項,與“補充”項中的初始化安全項對應
hr = RegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
if (FAILED(hr))
return hr;
return NOERROR;
}
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
//HRESULT hr;
AFX_MANAGE_STATE(_afxModuleAddrThis);
if (!AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor))
return ResultFromScode(SELFREG_E_TYPELIB);
if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
return ResultFromScode(SELFREG_E_CLASS);
//hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForInitializing);
//if (FAILED(hr))
//return hr;
//hr=UnRegisterCLSIDInCategory(CLSID_SafeItem, CATID_SafeForScripting);
//if (FAILED(hr))
//return hr;
return NOERROR;
}
HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription)
{
ICatRegister* pcr = NULL ;
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 (FAILED(hr))
return hr;
}
if (pcr != NULL)
pcr->Release();
return hr;
}
HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid)
{
ICatRegister* pcr = NULL ;
HRESULT hr = S_OK ;
hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr);
if (SUCCEEDED(hr))
{
// Unregister this category as being "implemented" by the class.
CATID rgcatid[1] ;
rgcatid[0] = catid;
hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid);
}
if (pcr != NULL)
pcr->Release();
return hr;
}
加入以上代碼後IE無任何警告,你可試一下,我用的沒問題