//注册事件
import win.ui;
/*DSG{{*/
var winform = win.form(text="用连接点注册事件";right=972;bottom=494)
winform.add(
edit={cls="edit";left=31;top=410;right=946;bottom=470;edge=1;multiline=1;vscroll=1;z=2};
static={cls="static";left=32;top=26;right=946;bottom=402;db=1;dl=1;dr=1;dt=1;edge=1;z=1}
)
/*}}*/

var embed = winform.static.createEmbed("Shell.Explorer.2"); 
var browser = embed._object;

//定义事件对象
DWebBrowserEvents2 = {
	BeforeNavigate2 = function( pDisp, url, flags, targetFrame, postData, headers, cancel ) { 
		winform.edit.print("BeforeNavigate2",url);
		return url, flags, targetFrame, postData, headers, cancel;
	}
	StatusTextChange = function(text) { 
		winform.text = text;
	}
}

/*
//注册事件
DWebBrowserEvents2 =  com.ImplInterface( DWebBrowserEvents2,"Shell.Explorer.2","DWebBrowserEvents2")
var cookie = com.AddConnection( browser,DWebBrowserEvents2 );

//释放事件
//com.ReleaseConnection(ie, DWebBrowserEvents2Handler, cookie)  
*/

//可以用上面的方法，也可以下面这样写简单一点
//var cookie = com.Connect(browser, DWebBrowserEvents2);

//winform.static.createEmbed() 实际已经自动执行了 com.Connect(embed._object, embed);
//所以更简单的方法如下：

embed.BeforeNavigate2 = function( pDisp, url, flags, targetFrame, postData, headers, cancel ) { 
	winform.edit.print("BeforeNavigate2",url);
	return url, flags, targetFrame, postData, headers, cancel;
}

embed.StatusTextChange = function(text) { 
	winform.text = text;
}

browser.Navigate("https://www.aardio.com");
	
winform.show(true); 
win.loopMessage();