首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

webBrowser中的有关问题,BHO、DispId的有关问题,做过的进来

2012-02-09 
webBrowser中的问题,BHO、DispId的问题,做过的进来这2段是从某个国外牛人写的代码中抄袭出来的,可以正常运

webBrowser中的问题,BHO、DispId的问题,做过的进来
这2段是从某个国外牛人写的代码中抄袭出来的,可以正常运行

//   COM   Event   Handler   for   HTML   Element   Events
[DispId(0)]
public   void   DefaultMethod()
{
//   obtain   the   event   object   and   ensure   a   context   menu   has   been   applied   to   the   document
HtmlEventObject   eventObject   =   document.parentWindow.@event;
string   eventType   =   eventObject.type;

//   Call   the   custom   Web   Browser   HTML   event  
ContextMenuShow(this,   eventObject);

}   //DefaultMethod


private   void   BrowserDocumentComplete(object   sender,   AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent   e)
{
//   get   access   to   the   HTMLDocument
document   =   (HtmlDocument)this.axWebBrowser1.Document;
//   add   style   sheet   link
string   href   =   Path.GetTempPath()   +   "/StyleMain.css ";
LinkStyleSheet(href);

body   =   (HtmlBody)document.body;

//   COM   Interop   Start
//   once   browsing   has   completed   there   is   the   need   to   setup   some   options
//   need   to   ensure   URLs   are   not   modified   when   html   is   pasted
IOleCommandTarget   target   =   null;
int   hResult   =   HRESULT.S_OK;
//   try   to   obtain   the   command   target   for   the   web   browser   document
try
{
//   cast   the   document   to   a   command   target
target   =   (IOleCommandTarget)document;
//   set   the   appropriate   no   url   fixups   on   paste
hResult   =   target.Exec(ref   CommandGroup.CGID_MSHTML,   (int)CommandId.IDM_NOFIXUPURLSONPASTE,   (int)CommandOption.OLECMDEXECOPT_DONTPROMPTUSER,   ref   EMPTY_PARAMETER,   ref   EMPTY_PARAMETER);
}
//   catch   any   exception   and   map   back   to   the   HRESULT
catch   (Exception   ex)
{
hResult   =   Marshal.GetHRForException(ex);
}
//   test   the   HRESULT   for   a   valid   operation
if   (hResult   ==   HRESULT.S_OK)
{
//   urls   will   not   automatically   be   rebased
rebaseUrlsNeeded   =   false;
}
else
{
//throw   new   HtmlEditorException(string.Format( "Error   executing   NOFIXUPURLSONPASTE:   Result   {0} ",   hResult));
rebaseUrlsNeeded   =   true;
}
//   COM   Interop   End

//   at   this   point   the   document   and   body   has   been   loaded
//   so   define   the   event   handler   as   the   same   class
//document.oncontextmenu   =   this;
((mshtml.DispHTMLDocument)document).oncontextmenu   =   this;
//   这句话是我加的,他只能相应DisoId(0)的方法
((mshtml.DispHTMLDocument)document).ondblclick   =   this;
//   complete


isloading   =   false;

}   //BrowserDocumentComplete

下面是我加的方法:
[DispId(3)]
public   void   WebDoubleClick()
{
HtmlEventObject   eventObject   =   document.parentWindow.@event;
string   eventType   =   eventObject.type;

MessageBox.Show( "Double   Click   :   "   +   eventType);
}

现象是只相应DispId(0)的方法,而我想双击触发DispId(3)的方法应该怎么做?

[解决办法]
我做过
GZ下
不过楼主可以看看 是否 有需要关联的事件委托需要申明

[解决办法]
学习,见意楼主把"抄袭"改为"抄写"
[解决办法]
好贴,学习
[解决办法]
帮你顶呀
[解决办法]
我用过 但是没有这么复杂的 ! 帮顶

[解决办法]
UP
[解决办法]
学习

热点排行