用 dhtml 写程序界面的问题(我会继续加分的)

gbstar2021 2001-06-08 01:33:00
向各位高手请教,在程序中使用webbrowse控件,窗口如何取得空间中显示的html页面的事件(如:按下某一个按钮).
...全文
205 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
让我试一试
kalling 2001-06-08
  • 打赏
  • 举报
回复
我会啊
主要过程是这样
1.实现一个eventsink类,(必须实现IDispatch接口)
2.通过IHTMLDocument2::all,得到所有元素的集合IHTMLElementCollection,然后找到所要的button的IHTMLElement接口,
void CMyClass::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IUnknown* pUnkDisp = NULL;
IDispatch* pDocDisp = NULL;
IHTMLDocument2* pDoc = NULL;

// Is this the DocumentComplete event for the top frame window?
// Check COM identity: compare IUnknown interface pointers.
hr = m_pBrowser->QueryInterface(IID_IUnknown, (void**)&pUnkBrowser);

if (SUCCEEDED(hr))
{
hr = pDisp->QueryInterface(IID_IUnknown, (void**)&pUnkDisp);

if (SUCCEEDED(hr))
{
if (pUnkBrowser == pUnkDisp)
{
// This is the DocumentComplete event for the top frame.
// This page is loaded, so we can access the DHTML Object Model.
hr = m_pBrowser->get_Document(&pDocDisp);

if (SUCCEEDED(hr))
{
// Obtained the document object.
pDocDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
if (SUCCEEDED(hr))
{
// Obtained the IHTMLDocument2 interface for the document object
ProcessDocument(pDoc);
}

pDocDisp->Release();
}
}

pUnkDisp->Release();
}

pUnkBrowser->Release();
}
}
void CMyClass::ProcessDocument(IHTMLDocument2* pDoc)
{
IHTMLElementCollection* pElemColl = NULL;

hr = pDoc->get_all(&pElemColl);
if (SUCCEEDED(hr))
{
// Obtained element collection.
ProcessElementCollection(pElemColl);
pElemColl->Release();
}
}
void CMyClass::ProcessElementCollection(IHTMLElementCollection* pElemColl)
{
IDispatch* pElemDisp = NULL;
IHTMLElement* pElem = NULL;
_variant_t varID("myID", VT_BSTR);
_variant_t varIdx(0, VT_I4);

hr = pElemColl->item(varID, varIdx, &pElemDisp);

if (SUCCEEDED(hr))
{
hr = pElemDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem);

if (SUCCEEDED(hr))
{
// Obtained element with ID of "myID".
ConnectEvents(pElem);
pElem->Release();
}

pElemDisp->Release();
}
}
3.QueryInterface,得到IConnectionPointContainer,然后connectionContainer.FindConnectionPoint (HTMLElementEvents2) 得到IConnectionPoint,然后IConnectionPoint::Advise(你的eventsink类的IUnknown接口)
void CMyClass::ConnectEvents(IHTMLElement* pElem)
{
HRESULT hr;
IConnectionPointContainer* pCPC = NULL;
IConnectionPoint* pCP = NULL;
DWORD dwCookie;

// Check that this is a connectable object.
hr = pElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);

if (SUCCEEDED(hr))
{
// Find the connection point.
hr = pCPC->FindConnectionPoint(DIID_HTMLElementEvents2, &pCP);

if (SUCCEEDED(hr))
{
// Advise the connection point.
// pUnk is the IUnknown interface pointer for your event sink
hr = pCP->Advise(pUnk, &dwCookie);

if (SUCCEEDED(hr))
{
// Successfully advised
}

pCP->Release();
}

pCPC->Release();
}
}

事件的触发回调用eventsink类的IDispatch::Invoke
STDMETHODIMP CEventSink::Invoke(DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS* pdispparams,
VARIANT* pvarResult,
EXCEPINFO* pexcepinfo,
UINT* puArgErr)
{
switch (dispidMember)
{
case DISPID_HTMLELEMENTEVENTS2_ONCLICK:
OnClick();
break;

default:
break;
}

return S_OK;
}
好好看看,肯定能做
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
真的没有人会吗? com 高手都那里去了。
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
没有人用 dhtml 做过程序界面吗 ?!
m$ 的很多程序都用了这种技术。
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
我的意思是说,在我的程序(exe or dll)中使用 web browse 控件
程序如何这个 click 事件呢?

(简单说就是,一个基于对话框的程序,在对话框上放了一个web browse 控件,我要让对话框可以处理 web 页面上的事件,该如何做呢?)
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
以下的vbs代码是 outlook 资源中的,在可执行的程序中如何响应按钮按下呢?

//------------------------------------------------------------------------------
// DoCommand
// Gives command signals to outlook by navigating
// values for number for each command are as follows
// number ==
// 0 -> User clicked the Find Now button
// 1 -> User clicked the Close button
// 2 -> User clicked the Advanced Find button
// 3 -> User wants to clear the search
// Author: JasonMo
//------------------------------------------------------------------------------
function DoCommand(number)
{
var sentence = "";

doaction.href = "outlcmd://";

if (number == 0)
doaction.href = doaction.href + "find/";

else if (number == 1) //close find
doaction.href = doaction.href + "close/";

else if (number == 2) //advanced find
doaction.href = doaction.href + "afindnor/";

else if (number == 3) //clear search
doaction.href = doaction.href + "clearfind/";

else if (number == 4) // user clicked the check box
doaction.href = doaction.href + "checkbox/"

else if (number == 5) // user clicked close
doaction.href = doaction.href + "close/"

doaction.click();
}
plato 2001-06-08
  • 打赏
  • 举报
回复
贴一个来自MSDN的例子
<BODY onmousedown="alert(event.srcElement.tagName)">
<TABLE BORDER=1>
<TH>Click the items below with your mouse.</TH>
<TR><TD><BUTTON>Click Me</BUTTON></TD></TR>
<TR><TD><INPUT TYPE=text VALUE="Click Me"></TD></TR>
<TR><TD><SPAN>Click Me</SPAN></TD></TR>
</TABLE>
<P>This code retrieves the tagName of the object on which
the onmousedown event has fired.
</BODY>
plato 2001-06-08
  • 打赏
  • 举报
回复
IHTMLDocument2中有设置onmousedown等事件Handler的方法,自己看看MSDN吧
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
像 outlook2000 (不是 outlook express)的搜索那样
用 dhtml 制作界面,在程序中相应事件,如何实现呢?
plato 2001-06-08
  • 打赏
  • 举报
回复
sorry,看错了,原来是要截获html中的按钮等事件啊?用DWebBrowserEvents2不行,
DWebBrowserEvents2只能截获浏览器消息(比如DocumentComplete)。
wuqingguo 2001-06-08
  • 打赏
  • 举报
回复
可能不行吧。
这涉及到了浏览器最底层的机制了。
gbstar2021 2001-06-08
  • 打赏
  • 举报
回复
不能再详细点吗?
plato 2001-06-08
  • 打赏
  • 举报
回复
给分吧,老大。
plato 2001-06-08
  • 打赏
  • 举报
回复
实现DWebBrowserEvents2接口,然后在这个类的构造函数中调用:
(注意,我是写的Java代码,如果用C++,形式上不同)
IConnectionPointContainer connectionContainer =
(IConnectionPointContainer)webBrowser ;
IConnectionPoint cp = connectionContainer.FindConnectionPoint
(DWebBrowserEvents2.iid) ;
cookie = cp.Advise(this) ;

其中,webBrowser是IWebBrowser2接口指针,怎么得到,不用我老人家说了吧?
coolstar 2001-06-08
  • 打赏
  • 举报
回复
guanzhu

604

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 控件与界面
社区管理员
  • 控件与界面社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧