如下例,想将控件的属性"Url"赋初值为"Init value",但结果没有成功:<OBJECT id=MyFirstCtrl name="MyFirstCtrl" classid="clsid:73658C38-032F-4A5F-9F8E-46F4B87C123D" codebase="MyFirstCtrl.ocx" width=200 height=200>
<PARAM name="Url" value="Init value">
</OBJECT>但是,下面的语句会成功:<SCRIPT language=javaScript>
<!--
window.MyFirstCtrl.Url="Reset value";
//-->
</SCRIPT>如何通过<PARAM name="..." value="...">给控件传递参数呢?
<PARAM name="Url" value="Init value">
</OBJECT>但是,下面的语句会成功:<SCRIPT language=javaScript>
<!--
window.MyFirstCtrl.Url="Reset value";
//-->
</SCRIPT>如何通过<PARAM name="..." value="...">给控件传递参数呢?
参数:hWnd,WebBrowser控件的窗口句柄
功能:通过WM_HTML_GETOBJECT取得控件的IHTMLDocument2接口
*/
IHTMLDocument2* GetDocInterface(HWND hWnd)
{
// 我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
IHTMLDocument2* pDoc2=NULL;
if ( hInst != NULL ){
if ( hWnd != NULL ){
CComPtr<IHTMLDocument> spDoc=NULL;
LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
::SendMessageTimeout( hWnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") );
if ( pfObjectFromLresult != NULL ){
HRESULT hr;
hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);
if ( SUCCEEDED(hr) ){
CComPtr<IDispatch> spDisp;
CComQIPtr<IHTMLWindow2> spWin;
spDoc->get_Script( &spDisp );
spWin = spDisp;
spWin->get_document( &pDoc2 );
}
}
}
::FreeLibrary(hInst);
}
else{//如果没有安装MSAA
AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
}
return pDoc2;
} /*函数名:GetDocInterfaceByMSAA
参数:hwnd,WebBrowser控件的窗口句柄
功能:取得hwnd对应的Webbrowser控件的IHTMLDocument2*接口.
*/
IHTMLDocument2* GetDocInterfaceByMSAA(HWND hwnd)
{
HRESULT hr;
HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") ); IHTMLDocument2* pDoc2=NULL;
if ( hInst != NULL ){
if ( hwnd != NULL ){
//取得AccessibleObjectFromWindow函数
LPFNACCESSIBLEOBJECTFROMWINDOW pfAccessibleObjectFromWindow =
(LPFNACCESSIBLEOBJECTFROMWINDOW)::GetProcAddress(hInst,_T("AccessibleObjectFromWindow"));
if(pfAccessibleObjectFromWindow != NULL){
CComPtr<IAccessible> spAccess;
hr=pfAccessibleObjectFromWindow(hwnd,0,
IID_IAccessible,(void**) &spAccess);//取得Webbrowser控件的IAccessible接口
if ( SUCCEEDED(hr) ){
CComPtr<IServiceProvider> spServiceProv;
hr=spAccess->QueryInterface(IID_IServiceProvider,(void**)&spServiceProv);
if(hr==S_OK){
CComPtr<IHTMLWindow2> spWin;
hr=spServiceProv->QueryService(IID_IHTMLWindow2,IID_IHTMLWindow2,
(void**)&spWin);
/*
注意:并不是每次都能取得IHTMLWindow2接口,如果调用失败,可以尝试取得IHTMLElement接口:
CComPtr<IHTMLElement> spElement;
hr=spServiceProv->QueryService(IID_IHTMLElement,IID_IHTMLElement,(void**)&spElement);
*/
if(hr==S_OK)
spWin->get_document(&pDoc2);
}
}
}
}
::FreeLibrary(hInst);
}
else{
AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
}
return pDoc2;
}
void CGetIhtmlDlg::GetPassword(IHTMLDocument2 *pDoc2,POINT pt)
{
if(pDoc2==NULL)
return;
//声明一个IHTMLElement接口指针
CComPtr<IHTMLElement> pElement;
//根据鼠标的位置获取接口
HRESULT hr=pDoc2->elementFromPoint(pt.x,pt.y,&pElement);
if(SUCCEEDED(hr))
{
//声明IHTMLInputTextElement接口指针
CComPtr<IHTMLInputTextElement> pPwdElement;
//查询该接口
hr=pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pPwdElement);
if(SUCCEEDED(hr))
{
CComBSTR type;
//获取网页元素的类型
hr=pPwdElement->get_type(&type);
if(SUCCEEDED(hr))
{
if(type==_T("password"))
{
CComBSTR pwd;
//获取密码输入框内的字符串
hr=pPwdElement->get_value(&pwd);
if(SUCCEEDED(hr))
{
if(pwd.Length()!=0){
CComBSTR msg=_T("密码是:");
msg+=pwd;
CString str(msg);
AfxMessageBox(str);
}
else
{
AfxMessageBox(_T("密码为空!"));
}
}
}
}
}
}
//释放
pDoc2->Release();
}
这是一个获得网页密码例子,将其中的get_value改成put_value就是设置密码
控件的Url属性也是通过 ClassWizard 自动加入的。 请问 IPersistPropertyBag 怎么用?我的工程中没有这个东东? 不胜感谢 !