Webbrowser的简单问题,高手请进(100分)

  • 主题发起人 主题发起人 hanmo
  • 开始时间 开始时间
H

hanmo

Unregistered / Unconfirmed
GUEST, unregistred user!
用Webbrowser做一个自动提交表单的东东,有的网页表单提交完成后弹出一个script窗口,得按'确定',如果不人工干预则无法进行下一步,我的问题是:如何用程序判断其弹出,并模拟按'确定'.对我来说很难.....试了如下的诸多方法,行不通:<br>1. 遍历所有窗口,可是因为不能确定弹出窗口的windowtext,所以找不到handle,<br>&nbsp; &nbsp;findwindow,Enumwindow不通<br>2. 判断弹出窗口是程序的Modalform,<br>&nbsp; from i:= to screen.formcount-1 do <br>&nbsp; begin <br>&nbsp; &nbsp; if fsModal in screen.forms.formstate then...<br>&nbsp; 却不能捕捉的到.<br>3.Webbrowse.silent:=true没有用的<br>&nbsp;期盼高手,急急急!!!<br><br>
 
看看javescript的涵數,應該有可以解決的...
 
IDocHostUIHandler有个方法叫EnableModeless(const fEnable: BOOL): HRESULT; stdcall;<br>师父可以帮助你,当弹出模式窗口的时候fEnable为true<br>关闭的时候为false<br><br>接口的定义如下:<br>&nbsp; IDocHostUIHandler = interface(IUnknown)<br>&nbsp; &nbsp; ['{bd3f23c0-d43e-11cf-893b-00aa00bdce1a}']<br>&nbsp; &nbsp; function ShowContextMenu(const dwID: DWORD; const ppt: PPOINT;<br>&nbsp; &nbsp; &nbsp; const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall;<br>&nbsp; &nbsp; function GetHostInfo(var pInfo: TDOCHOSTUIINFO): HRESULT; stdcall;<br>&nbsp; &nbsp; function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;<br>&nbsp; &nbsp; &nbsp; const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;<br>&nbsp; &nbsp; &nbsp; const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall;<br>&nbsp; &nbsp; function HideUI: HRESULT; stdcall;<br>&nbsp; &nbsp; function UpdateUI: HRESULT; stdcall;<br>&nbsp; &nbsp; function EnableModeless(const fEnable: BOOL): HRESULT; stdcall;<br>&nbsp; &nbsp; function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall;<br>&nbsp; &nbsp; function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall;<br>&nbsp; &nbsp; function ResizeBorder(const prcBorder: PRECT;<br>&nbsp; &nbsp; &nbsp; const pUIWindow: IOleInPlaceUIWindow;<br>&nbsp; &nbsp; &nbsp; const fRameWindow: BOOL): HRESULT; stdcall;<br>&nbsp; &nbsp; function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID;<br>&nbsp; &nbsp; &nbsp; const nCmdID: DWORD): HRESULT; stdcall;<br>&nbsp; &nbsp; function GetOptionKeyPath(var pchKey: POLESTR; const dw: DWORD): HRESULT; stdcall;<br>&nbsp; &nbsp; function GetDropTarget(const pDropTarget: IDropTarget;<br>&nbsp; &nbsp; &nbsp; out ppDropTarget: IDropTarget): HRESULT; stdcall;<br>&nbsp; &nbsp; function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall;<br>&nbsp; &nbsp; function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POLESTR;<br>&nbsp; &nbsp; &nbsp; var ppchURLOut: POLESTR): HRESULT; stdcall;<br>&nbsp; &nbsp; function FilterDataObject(const pDO: IDataObject;<br>&nbsp; &nbsp; &nbsp; out ppDORet: IDataObject): HRESULT; stdcall;<br>&nbsp; end;<br>&nbsp; <br>&nbsp; ICustomDoc=interface(IUnknown)<br>&nbsp; &nbsp; ['{3050f3f0-98b5-11cf-bb82-00aa00bdce0b}']<br>&nbsp; &nbsp; function SetUIHandler(const pUIHandler:IDocHostUIHandler):HRESULT; stdcall;<br>&nbsp; end;<br>
 
to satanmonkey:<br>我是新手,对接口不熟,<br>1.我上面已说当成模式窗口捕捉不到<br>2.可不可以告诉我详细实现方法<br>
 
你做这个应该用BHO的吧?BHO的setsite里会传过来一个iwebbrowser2接口,里存下来以后,得到他的ICustomDoc接口,就可以用ICustomDoc的SetUIHanlder替换IE的IDocHostUIHandler
 
给里段C++代码参考<br><br> case DISPID_DOCUMENTCOMPLETE:<br> ATLTRACE(_T("(%ld) DISPID_DOCUMENTCOMPLETE/n"), ::GetCurrentThreadId());<br><br> m_bHotkeysEnabled = FALSE; // Deactivate keyboard hook<br> m_bUserClickedLink = FALSE; // Reset<br><br> {<br> CConnInfo* pConnInfo = new CConnInfo(pDispParams-&gt;rgvarg[1].pdispVal);<br> if (pConnInfo)<br> {<br> m_deqEventHandlers.push_back(pConnInfo);<br> ManageEventHandlers(pConnInfo, ConnType_Advise);<br> }<br> }<br><br> if (m_pWBDisp &amp;&amp; <br> m_pWBDisp == pDispParams-&gt;rgvarg[1].pdispVal)<br> {<br> // If the LPDISPATCH are same, that means<br> // it is the final DocumentComplete. Reset m_pWBDisp.<br> ATLTRACE(_T("(%ld) DISPID_DOCUMENTCOMPLETE (final)/n"), <br> ::GetCurrentThreadId());<br> m_pWBDisp = NULL;<br><br> CComPtr&lt;IDispatch&gt; spDisp;<br> HRESULT hr = m_spWebBrowser2-&gt;get_Document(&amp;spDisp);<br> if (SUCCEEDED(hr) &amp;&amp; spDisp)<br> {<br> BOOL bMustAdvise = FALSE;<br> if (m_spHTMLDocument &amp;&amp; <br> m_spHTMLDocument != spDisp)<br> {<br> ATLTRACE(_T("(%ld) DISPID_DOCUMENTCOMPLETE (unadvising)/n"), <br> ::GetCurrentThreadId());<br> <br> HRESULT hr = ManagePropertyNotifyConnection(ConnType_Unadvise);<br> ATLASSERT(SUCCEEDED(hr));<br><br> m_spHTMLDocument = spDisp;<br> if (m_spHTMLDocument)<br> {<br> hr = ManagePropertyNotifyConnection(ConnType_Advise);<br> ATLASSERT(SUCCEEDED(hr));<br> }<br> }<br> else if (!m_spHTMLDocument)<br> {<br> m_spHTMLDocument = spDisp;<br> if (m_spHTMLDocument)<br> {<br> hr = ManagePropertyNotifyConnection(ConnType_Advise);<br> ATLASSERT(SUCCEEDED(hr));<br> }<br> }<br><br> if (m_spHTMLDocument)<br> {<br> // This is an HTML document (e.g., it's a <br> // Word doc or a PDF), go ahead and sink.<br> hr = m_spHTMLDocument-&gt;get_parentWindow(&amp;m_pHTMLWindow);<br> ATLASSERT(SUCCEEDED(hr) &amp;&amp; m_pHTMLWindow);<br> if (FAILED(hr))<br> m_pHTMLWindow = NULL;<br><br> // Get pointers to default interfaces<br> CComQIPtr&lt;IOleObject, &amp;IID_IOleObject&gt; spOleObject(spDisp);<br> if (spOleObject)<br> {<br> CComPtr&lt;IOleClientSite&gt; spClientSite;<br> hr = spOleObject-&gt;GetClientSite(&amp;spClientSite);<br> if (SUCCEEDED(hr) &amp;&amp; spClientSite)<br> {<br> m_spDefaultDocHostUIHandler = spClientSite;<br> m_spDefaultOleCommandTarget = spClientSite;<br> }<br> }<br><br> // Set this class to be the IDocHostUIHandler<br> CComQIPtr&lt;ICustomDoc, &amp;IID_ICustomDoc&gt; spCustomDoc(spDisp);<br> if (spCustomDoc)<br> {<br> hr = spCustomDoc-&gt;SetUIHandler(this);<br> ATLASSERT(SUCCEEDED(hr));<br> }<br><br> // Create a CPubDomExtender object that will be used by<br> // window.external<br> CComObject&lt;CPubDomExtender&gt;* pDomExt;<br> hr = CComObject&lt;CPubDomExtender&gt;::CreateInstance (&amp;pDomExt);<br> ATLASSERT(SUCCEEDED(hr));<br> if (SUCCEEDED(hr))<br> {<br> CComQIPtr&lt;IDispatch&gt; spDisp = pDomExt;<br> m_spExtDispatch = spDisp;<br> pDomExt-&gt;m_pPub = this;<br> }<br><br> // Check for flash here because READYSTATE_COMPLETE<br> // seems to be unreliable.<br> if (IsEnabled() &amp;&amp; !IsSiteWhiteListed())<br> {<br> DWORD dwElemTypes = 0;<br> if (g_bBlockFlash)<br> dwElemTypes |= ELEMTYPE_FLASH;<br> if (g_bBlockImages)<br> dwElemTypes |= ELEMTYPE_IMAGES;<br> BlockWebPageElements(dwElemTypes);<br> }<br> }<br> } <br> }<br> m_bHotkeysEnabled = TRUE;<br> break;<br>
 
thank satanmonkey,可惜本人水平太浅,希望有更简单的方法
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部