//网页探针
import key;
import mouse
import winex;
import win.cur;
import web.util 
import web.access;
import win.util.tray; 
import web.form.util;
import win.ui.menu;
/*DSG{{*/
var winform = win.form(parent=...; right=712;bottom=459;scroll=1;text="网页探针 2.8  -  使用AAuto语言开发,支持外部浏览器窗口";border="resizable" )
winform.add( 
editUrl={ dr=1;dl=1;bottom=36;text="http://www.aau.cn";left=9;dt=1;top=11;z=14;right=216;edge=1;cls="edit" };
btnforward={ dr=1;bottom=36;text=">>";left=313;dt=1;top=11;z=9;right=343;cls="button" };
btnHelp={ dr=1;disabled=1;bottom=394;right=707;left=654;top=368;z=13;db=1;text="相关";cls="button" };
lbWeb={ dr=1;dl=1;text="";notify=1;bottom=365;right=706;left=9;dt=1;top=42;transparent=1;db=1;z=1;edge=1;cls="static" };
editCode={ dr=1;dl=1;vscroll=1;color=0;right=647;left=9;db=1;cls="richedit";bottom=453;text="";multiline=1;top=368;font=LOGFONT( name='Microsoft Sans Serif' );z=2;hscroll=1;edge=1 };
editX={ dr=1;bottom=33;text="";left=471;dt=1;top=13;z=3;right=512;multiline=1;edge=1;cls="edit" };
static2={ dr=1;bottom=40;align="right";right=472;left=333;dt=1;top=18;font=LOGFONT( name='Microsoft Sans Serif' );z=5;text="ele = wb.fromPoint(  ";color=0;transparent=1;cls="static" };
btnGo={ dr=1;bottom=36;text="打开";left=228;dt=1;top=11;z=15;right=275;cls="button" };
chkFrameContent={ dr=1;checked=1;bottom=36;text="穿透框架-->";left=584;dt=1;top=10;z=10;right=660;cls="checkbox" };
static3={ dr=1;bottom=40;align="right";right=521;left=515;dt=1;top=18;font=LOGFONT( name='Microsoft Sans Serif' );z=6;text=",";color=0;transparent=1;cls="static" };
btnSaveAs={ dr=1;bottom=424;text="复制";left=654;top=398;z=11;db=1;right=707;cls="button" };
editY={ dr=1;bottom=33;text="";left=524;dt=1;top=13;z=4;right=565;multiline=1;edge=1;cls="edit" };
picturebox={ dr=1;notify=1;right=700;left=665;dt=1;top=7;z=7;bottom=39;transparent=1;cls="picturebox" };
btnback={ dr=1;bottom=36;text="<<";left=279;dt=1;top=11;z=8;right=309;cls="button" };
btnRun={ dr=1;bottom=453;text="运行(F5)";left=654;top=427;z=12;db=1;right=707;cls="button" }
)
/*}}*/

//创建web窗体
var wb = web.form( winform.lbWeb );
winform._localWb = wb;

wb.noScriptErr=true;//禁止脚本错误

wb.BeforeNavigate2=function( pDisp, url, Flags, TargetFrameName, PostData, Headers, Cancel ) { 
	winform.spyElement = null;
	winform.spyWb = null;
	winform.spyHwnd = null;
	winform.spyElement = null;
	winform.spying = null;
} 

//开启框架跨域支持
web.form.util.crossDomain();
 
winform.btnRun.oncommand = function(id,event){
	global.wb = winform.spyWb;
	global.winform = winform; 
	
	var func,err = loadcode(winform.editCode.text)
	if(!func){
		if( string.find( winform.editCode.text,"/**") )
			winform.msgbox(err,"载入代码时遇到错误","网页探针")
		else {
			winform.msgbox( "请先拖动右上角瞄准器图标到网页上以选定对象.","网页探针")
		}
		
		return;
	}
	func()
} 

//点击网页时，缩小文本框
winform.lbWeb.wndproc = function(hwnd,message,wParam,lParam){
	if( message == 0x21/*_WM_MOUSEACTIVATE*/)
		winform.editCode.resize(false); 
}
 
winform.btnHelp.oncommand = function(id,event){
	var url = string.format("http://www.aau.cn/doc/html/dhtml/objects/%s.html", string.lower(winform.spyElement.tagName) )
	web.util.ieBrowser(url)
} 
 
//打开网页时触发
wb.NavigateComplete2=function(pDisp, url) {
	winform.editUrl.text = wb.location; 
}  

wb.NewWindow2=function( ppDisp, Cancel) {
	/*弹出新窗口以前触发 */ 
	return owner.openproxy /*创建代理窗口捕获网址并在当前窗口打开*/	
} 
wb.CommandStateChange=function(cmd,enable) {
	/*当命令的激活状态改变时触发。它表明何时激活或关闭Back和Forward菜单项或按钮 */ 
	select(cmd) {
	
	 	case 0x2/*_CSC_NAVIGATEBACK*/ {
	 		winform.btnback.disabled = !enable 
	 		
	 	}
	 	case 0x1/*_CSC_NAVIGATEFORWARD*/ {
	 		winform.btnforward.disabled = !enable 
	 	}  
	}
} 
	 
onmousemove = com.ImplInterface( 
   function(event){	 
		if( key.getState("CTRL") ){
			winform.editX.text = event.clientX;
			winform.editY.text = event.clientY;
			winform.editCode.text = event.srcElement.outerHTML 
			winform.spyElement = event.srcElement 
			winform.spyWb = wb;
			winform.btnHelp.disabled = false
			
			winform.spying = true;
		}
		else {
			winform.spying = false; 
		} 
		
	}
)
wb.DocumentComplete=function( pDisp, url) { 

	/*当整个文档完成时触发，刷新页面不触发*/
	var doc = pDisp.Document;
	if( type(doc) ==type.function )
		doc = doc();
		
	doc.attachEvent("onmousemove",onmousemove)  
} 

winform.btnGo.oncommand = function(id,event){
	wb.go(winform.editUrl.text) 
	var doc = wb.waitDoc()
	doc.attachEvent("onmousemove",onmousemove)  
}
winform.btnforward.oncommand = function(id,event){
	wb.goforward()
	var doc = wb.waitDoc()
	doc.attachEvent("onmousemove",onmousemove)  
}
winform.btnback.oncommand = function(id,event){ 
	wb.goback() 
	var doc = wb.waitDoc()
	doc.attachEvent("onmousemove",onmousemove)  
} 

//-------------------------------------------------
//内存图像 - 创建自"工具->转义字符串生成器"
gifCur = 'GIF\56\57a \0 \0\x91\0\0\xc0\xc0\xc0\0\0\xff\0\0\0\xff\xff\xff\33\xff\11XMP DataXMP<?xpacket begin=\34\xef\xbb\xbf\34 id=\34W\53M\48MpCehiHzreSzNTczkc\57d\34?> <x:xmpmeta xmlns:x=\34adobe:ns:meta\47\34 x:xmptk=\34Adobe XMP Core \53\46\48\45c\48\54\48 \54\49\46\49\51\52\55\55\55\44 \50\48\49\48\47\48\50\47\49\50\45\49\55:\51\50:\48\48		\34> <rdf:RDF xmlns:rdf=\34http:\47\47www\46w\51\46org\47\49\57\57\57\47\48\50\47\50\50\45rdf\45syntax\45ns\35\34> <rdf:Description rdf:about=\34\34 xmlns:xmp=\34http:\47\47ns\46adobe\46com\47xap\47\49\46\48\47\34 xmlns:xmpMM=\34http:\47\47ns\46adobe\46com\47xap\47\49\46\48\47mm\47\34 xmlns:stRef=\34http:\47\47ns\46adobe\46com\47xap\47\49\46\48\47sType\47ResourceRef\35\34 xmp:CreatorTool=\34Adobe Photoshop CS\53 Windows\34 xmpMM:InstanceID=\34xmp\46iid:\57\50E\56\53\49\55\48\57D\50\57\49\49DFA\52F\52ED\48\52\51\56\52\57\56EB\54\34 xmpMM:DocumentID=\34xmp\46did:\57\50E\56\53\49\55\49\57D\50\57\49\49DFA\52F\52ED\48\52\51\56\52\57\56EB\54\34> <xmpMM:DerivedFrom stRef:instanceID=\34xmp\46iid:\57\50E\56\53\49\54E\57D\50\57\49\49DFA\52F\52ED\48\52\51\56\52\57\56EB\54\34 stRef:documentID=\34xmp\46did:\57\50E\56\53\49\54F\57D\50\57\49\49DFA\52F\52ED\48\52\51\56\52\57\56EB\54\34\47> <\47rdf:Description> <\47rdf:RDF> <\47x:xmpmeta> <?xpacket end=\34r\34?>\1\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0\xef\xee\xed\xec\xeb\xea\xe9\xe8\xe7\xe6\xe5\xe4\xe3\xe2\xe1\xe0\xdf\xde\xdd\xdc\xdb\xda\xd9\xd8\xd7\xd6\xd5\xd4\xd3\xd2\xd1\xd0\xcf\xce\xcd\xcc\xcb\xca\xc9\xc8\xc7\xc6\xc5\xc4\xc3\xc2\xc1\xc0\xbf\xbe\xbd\xbc\xbb\xba\xb9\xb8\xb7\xb6\xb5\xb4\xb3\xb2\xb1\xb0\xaf\xae\xad\xac\xab\xaa\xa9\xa8\xa7\xa6\xa5\xa4\xa3\xa2\xa1\xa0\x9f\x9e\x9d\x9c\x9b\x9a\x99\x98\x97\x96\x95\x94\x93\x92\x91\x90\x8f\x8e\x8d\x8c\x8b\x8a\x89\x88\x87\x86\x85\x84\x83\x82\x81\x80\x7f\x7e}|{zyxwvutsrqponmlkjihgfedcba`_^]\\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:\57\56\55\54\53\52\51\50\49\48\47\46\45\44\43\42\41\40\39\38%\36\35\34\33 \31\30\29\28\27\26\25\24\23\22\21\20\19\18\17\16\15\14\13\12\11\10\9\8
\7\6\5\4\3\2\1\0\0\33\xf9\4\0\0\0\0\0\44\0\0\0\0 \0 \0\0\2\x8d\x94\x8f\xa9\x9b\xe0 \x82\x9c\xb4V\xf1 \54\xd0z\xbf\x85Y\xf4\x95\18\xf6\48\xea\xba\12\xee\11\xc7\xf2\xec\26\xf4\x8d\xbfv\xce\xcb{\15\28\xfc\x82\xbc\33\45\xd1\51\xc6v\x82Z\19\xa7\xd4\57\15\53\xe8\xd3\xb7\xcc\30\xaf\48\46R:\x8br\xabZ\xdfX\x88\x7eR\xd3h\51\xb6\9\x97\xc6\xcf\xc2s\11\xae\8\xdb\xd9\xd7y{\xb9\23W\xa7\xc6\xe6\x86U\6f\x88\xf8E\xa6\x88\xf8\xd7\xe8\xa8\xf5E\xa7S\xe9D\22\xd5ui\xb9\x96\xa3I\36\25\xba\53Z\xc4Y:\xc8\xa2\xbaP\0\0;'
gifBlank ='GIF\56\57a \0 \0\x91\0\0\xc0\xc0\xc0\0\0\xff\0\0\0\xff\xff\xff\33\xff\11XMP DataXMP<?xpacket begin=\34\xef\xbb\xbf\34 id=\34W\53M\48MpCehiHzreSzNTczkc\57d\34?> <x:xmpmeta xmlns:x=\34adobe:ns:meta\47\34 x:xmptk=\34Adobe XMP Core \53\46\48\45c\48\54\48 \54\49\46\49\51\52\55\55\55\44 \50\48\49\48\47\48\50\47\49\50\45\49\55:\51\50:\48\48		\34> <rdf:RDF xmlns:rdf=\34http:\47\47www\46w\51\46org\47\49\57\57\57\47\48\50\47\50\50\45rdf\45syntax\45ns\35\34> <rdf:Description rdf:about=\34\34 xmlns:xmp=\34http:\47\47ns\46adobe\46com\47xap\47\49\46\48\47\34 xmlns:xmpMM=\34http:\47\47ns\46adobe\46com\47xap\47\49\46\48\47mm\47\34 xmlns:stRef=\34http:\47\47ns\46adobe\46com\47xap\47\49\46\48\47sType\47ResourceRef\35\34 xmp:CreatorTool=\34Adobe Photoshop CS\53 Windows\34 xmpMM:InstanceID=\34xmp\46iid:\57CCE\48\56\52\57\57D\50\57\49\49DF\56\57BEE\49D\56\49\48\48D\51EA\55\34 xmpMM:DocumentID=\34xmp\46did:\57CCE\48\56\52A\57D\50\57\49\49DF\56\57BEE\49D\56\49\48\48D\51EA\55\34> <xmpMM:DerivedFrom stRef:instanceID=\34xmp\46iid:\57CCE\48\56\52\55\57D\50\57\49\49DF\56\57BEE\49D\56\49\48\48D\51EA\55\34 stRef:documentID=\34xmp\46did:\57CCE\48\56\52\56\57D\50\57\49\49DF\56\57BEE\49D\56\49\48\48D\51EA\55\34\47> <\47rdf:Description> <\47rdf:RDF> <\47x:xmpmeta> <?xpacket end=\34r\34?>\1\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0\xef\xee\xed\xec\xeb\xea\xe9\xe8\xe7\xe6\xe5\xe4\xe3\xe2\xe1\xe0\xdf\xde\xdd\xdc\xdb\xda\xd9\xd8\xd7\xd6\xd5\xd4\xd3\xd2\xd1\xd0\xcf\xce\xcd\xcc\xcb\xca\xc9\xc8\xc7\xc6\xc5\xc4\xc3\xc2\xc1\xc0\xbf\xbe\xbd\xbc\xbb\xba\xb9\xb8\xb7\xb6\xb5\xb4\xb3\xb2\xb1\xb0\xaf\xae\xad\xac\xab\xaa\xa9\xa8\xa7\xa6\xa5\xa4\xa3\xa2\xa1\xa0\x9f\x9e\x9d\x9c\x9b\x9a\x99\x98\x97\x96\x95\x94\x93\x92\x91\x90\x8f\x8e\x8d\x8c\x8b\x8a\x89\x88\x87\x86\x85\x84\x83\x82\x81\x80\x7f\x7e}|{zyxwvutsrqponmlkjihgfedcba`_^]\\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:\57\56\55\54\53\52\51\50\49\48\47\46\45\44\43\42\41\40\39\38%\36\35\34\33 \31\30\29\28\27\26\25\24\23\22\21\20\19\18\17\16\15\14\13\12\11\10\9\8\7\6\5\4\3\2\1\0\0\33
\xf9\4\0\0\0\0\0\44\0\0\0\0 \0 \0\0\2\\\x94\x8f\xa9\x9b\xe0 \x82\x9c\xb4V\xf1 \54\xd0z\xbf\x85Y\xf4\x95\18\xf6\48\xea\xba\12\xee\11\xc7\xf2\xec\26\xf4\x8d\xbfv\xce\xcb{\15\28\xfc\x82\xbc\33\17g<\xd2\x92J\x9f\xa0\x99cBu\xcf\xe9\xb2jufgRkw\xfa\x85\x86\x9bce\xf9x\38\xa6\x83k`\xbb\xf7\46b\xb7Tz\x8c\x85_\21\0\0;'

var ipic =com.picture.load( '\0\0\2\0\1\0  \2\0\16\0\16\0\48\1\0\0\22\0\0\0\40\0\0\0 \0\0\0@\0\0\0\1\0\1\0\0\0\0\0\0\1\0\0\0\0\0\0\0\0\0\0\2\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfc\31\xff\xff\xf3g\xff\xff\xec\27\xff\xff\xdf}\xff\xff\x9c\30\xff\xff\x9f\x7e\xff\xffV\53\x7f\xffU\xd5\x7f\xff\1@\x7f\xffU\xd5\x7f\xffV\53\x7f\xff\xbf\x7e\xff\xff\xbc\30\xff\xff\xdf}\xff\xff\xec\27\xff\xff\xf3g\xff\xff\xfc\31\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff')
var hCursor = topointer( ipic.CopyHandle()  )
//------------------------------------------------- 

var crossHtmlTemplate = /***
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=%s" />
<BASE HREF="%s" /> 
</head>
<body>
<div style='font:12px/1.3em;margin:5px;'>
	%s
<div>
</body>
</html>
***/ 
  
genCode = function(){
	winform.spyElement = null;
	winform.spyWb = null;
	winform.spyHwnd = null;
	winform.spyElement = null;
	winform.spying = null;
	   
	var x, y = mouse.getPos();
	var spyHwnd = winex.fromPoint(x, y);
	if (!spyHwnd) return; 
	
	if( win.getClass(spyHwnd) == "Chrome_RenderWidgetHostHWND"){
		win.util.tray.pop("谷歌浏览器不支持此程序","网页表单神捕")
	}
	if (win.getClass(spyHwnd) != "Internet Explorer_Server") 
		return;
	
	var wb = wb;
	
	x,y = win.toClient(spyHwnd,x,y)

	if( win.getThreadProcessId(spyHwnd)  != win.getThreadProcessId( winform.lbWeb.hwnd ) ){
		wb = web.access( spyHwnd )     
		winform.crossProcess = true;
	}
	else {
		winform.crossProcess = false;
	}
	
		
	if (!wb) 
		return;
	
	if(!wb.document)
		return;
		
	var docEle = wb.document.documentElement;
	if(!docEle){
		return ; 
	}  
	
	var ele = wb.fromPoint(x,y);
	if( !ele ){
		return;
	};
	
	var eleFrame;
	var frameName = ""; 
	var frameNameWithComma = "";
	var scrollTop = docEle.scrollTop 
	var scrollLeft = docEle.scrollLeft  
	if( winform.chkFrameContent.checked ){
		  
		if(ele.tagName="IFRAME" || ele.tagName="FRAME"  ){ 
			var l,t = wb.getPoint(ele); 
			x = x-( l - wb.document.documentElement.scrollLeft );
			y = y-( t - wb.document.documentElement.scrollTop ); 
			
			//跨域支持
			doc = wb.getDoc( ele )  
			var eleNext = doc.elementFromPoint(x,y  ); 
			if(eleNext){ 
				var scrollTop = wb.document.documentElement.scrollTop
				var scrollLeft = wb.document.documentElement.scrollLeft
		
				eleFrame = ele;
				frameName = eleFrame.name||eleFrame.id 
				if(#frameName)
					frameNameWithComma = ',"'+frameName+'"' 
				else{ 
					var frames = eleFrame.ownerDocument.frames;
					for(i=0;frames.length-1){   
						var doc = wb.getDoc(frames(i))
						if( com.topointer(doc) == com.topointer(eleNext.ownerDocument) ){
							frameNameWithComma = ','+tostring(i)
							break;
						}
			 		
					}
			   		
				}
				
				ele = eleNext;
			}
			
		}
	}

	if(!ele.outerHTML)
		return; 
	var str = string.trim( ele.outerHTML  )
	if( winform.crossProcess ){
		var sypHtml = string.replace(str,"@<","&lt;")
		sypHtml = string.replace(sypHtml,"@<","&gt;")
		sypHtml = "<span style='font-size:10.5pt;'>" + sypHtml + "</span><br /><br />" + str ;
		var html = string.format(crossHtmlTemplate,wb.document.charSet,wb.location,sypHtml)
		winform._localWb.write(html);
	}
		
 	winform.spyElement = ele
 	winform.btnHelp.disabled = false
 	 
 	var e_x,e_y,e_cx,e_cy = wb.getPos(ele,true) 
 	flashRect( ::RECT(e_x,e_y,e_x+e_cx+4,e_y+e_cy+4) )  
 
	if(   ! ( ele.id || ele.name )   ){ 
		var queryOption = {}
		queryOption.className = ele.className;
		queryOption.innerHTML = ele.innerHTML;
		if( queryOption.innerHTML  ){
			queryOption.innerHTML  = string.left(queryOption.innerHTML ,50,true);
			if( string.find(queryOption.innerHTML,"\p")  )
				queryOption.innerHTML  = "@" + queryOption.innerHTML ;
		}
		
		queryOption.src = ele.src;
		if( queryOption.src  ){
			queryOption.src  = string.right(queryOption.src ,10,true);
			queryOption.src  = "@" + queryOption.src ;
		}
		else{
			queryOption.href = ele.href;
			if( queryOption.href  ){
				queryOption.href  = string.right(queryOption.href ,50,true);
				queryOption.href  = "@" + queryOption.href ;
			}
		} 
		
		queryOption.tagName = ( (#ele.tagName) > 1 )?ele.tagName : ( "^" + ele.tagName + "$" );
		if( #frameName ){ 
			qFrameName = string.trim(frameName,",");
			queryOption.parent = frameName;
		} 
		 
		str = string.concat('var ele = wb.queryEles( '
			,string.trim( table.tostring(queryOption),"{}" )
			,' );\r\n//ele.innerHTML="新的值";'
		);  
	}
	else{ 
		var strGetEle = string.concat('var ele = wb.getEle("',ele.id || ele.name ,'"',frameNameWithComma,')  ');
		if( ele.tagName == "SELECT"){
			strGetEle = string.concat('var ele = wb.select("'
						,ele.id || ele.name
						,'","'
						,ele.value
						,'"'
						,#frameNameWithComma?",true":""
						,frameNameWithComma
						,') //获取命名对象')
		}
		elseif( ele.tagName == "INPUT"){ 
			select(ele.type) { 
				case "radio","checkbox" {
					strGetEle = string.concat('var eles = wb.getEles("',ele.id || ele.name,'"',frameNameWithComma,') //获取命名对象\r\nvar ele = eles(0)\r\nele.checked = true;');
				} 
				else {
					strGetEle = string.concat(strGetEle,'\r\nele.value = "',ele.value : "输入新的值",'"')
				}; 
			};
		}
		str = string.concat("/** ",str,' **/\r\n',strGetEle);
	} 

	str = str  + "
import win.util.tray;//导入汽球提示支持库
win.util.tray.pop( ele.value || ele.innerHTML || ele.outerHTML ) //看看节点取的是否正确"
	
	winform.editCode.text = str
	winform.editX.text = x;
	winform.editY.text = y; 
	winform.spying = true; 
	winform.spyWb = wb;
	winform.spyHwnd = spyHwnd; 
}

var timeSpyId;
winform.picturebox.image = gifCur
winform.picturebox.wndproc = function (hwnd,message,wParam,lParam){
	select (message){
		case 0x201/*_WM_LBUTTONDOWN*/{
		
			if(timeSpyId)
				return;
				
			winform.editCode.resize(false)
			
			winform.picturebox.image = gifBlank;  
			winform.picturebox.capture = true;
			win.cur.beginCur(hCursor);//持续设定鼠标指针
			 
			winform.spying = true;  
			
			timeSpyId = winform.addtimer(
				500/*毫秒*/,
				function(hwnd,msg,id,tick){//定时执行代码
					genCode()
					winform.spying = true;
				}
			);
		}
		case 0x202/*_WM_LBUTTONUP*/{ 
			if( timeSpyId ){ 
				winform.killtimer(timeSpyId)
				winform.picturebox.image = gifCur; 
				winform.picturebox.capture = false
				win.cur.endCur(); //恢复正常鼠标指针 
				genCode()
				winform.editCode.resize(true)
				winform.spying = false;
				timeSpyId = null;
			}
		}  
	}
}

//开启自动完成
::Shlwapi := ..raw.loadDll("Shlwapi.dll")
SHAutoComplete = ::Shlwapi.api("SHAutoComplete","int(int hwndEdit,int dwFlags)")
SHAutoComplete( winform.editUrl.hwnd,0/*_SHACF_DEFAULT*/);

//在文本框获得焦点时,自动扩大
winform.editCode.max = false;
winform.editCode.resize = function(focus){
	if(focus){
		var wb_x,wb_y,wb_cx,wb_cy = winform.lbWeb.getPos()
		var x,y,cx,cy = winform.editCode.getPos()
		if(winform.editCode.max)
			return;
			
		winform.lbWeb.setPos(wb_x,wb_y,wb_cx,wb_cy-(wb_cy/2)); 
	 	winform.editCode.setPos(x,y-(wb_cy/2),cx,cy+(wb_cy/2)) 
	 	winform.editCode.max = true;
	}  
	else{
		var wb_x,wb_y,wb_cx,wb_cy = winform.lbWeb.getPos()
		var x,y,cx,cy = winform.editCode.getPos()
		if(!winform.editCode.max)
			return;
			
		winform.lbWeb.setPos(wb_x,wb_y,wb_cx,wb_cy+wb_cy); 
	 	winform.editCode.setPos(x,y+wb_cy,cx,cy-wb_cy) 	
	 	winform.editCode.max = false
	}
}

winform.editCode.oncommand = function(id,event){
	if(event == 0x100/*_EN_SETFOCUS*/){
		winform.editCode.resize(true)
	}  
	elseif(event == 0x200/*_EN_KILLFOCUS*/){
		winform.editCode.resize(false)
	}
}

template = /**
import win.ui;
/*DSG{{*/
var winform = win.form(parent=...; scroll=1;text="AAuto Form";right=349;bottom=249 )
winform.add(  )
/*}}*/

import web.form;

//创建web窗体
var wb = web.form( winform 
	,//可输入_UIFLAG_ 前缀的常量自定义外观
	,//可输入_DLCTL_ 前缀的常量以控制下载行为
	,//"USER AGENT"
	);

//打开目标网站
wb.go("**/

template2 =/**
")
//显示窗体
winform.show() 
winform.setPos($$X,$$Y,$$CX,$$CY)
wb.wait("");//等待指定网址,可以使用模式匹配语法

$$GETELE

//进入消息循环
win.loopMessage();
return winform,wb;

**/

var getWebFormCode = function(){
	var str = winform.editCode.text
	var code = template ++ winform.editUrl.text ++ template2;
	var x,y,cx,cy = winform.getPos()
	code = string.replace(code,"@$$X",x);
	code = string.replace(code,"@$$Y",x);
	code = string.replace(code,"@$$CX",cx);
	code = string.replace(code,"@$$CY",cy);
	str = string.replace(code,"@$$GETELE",str)	
	return str;
}


import win.clip
winform.btnSaveAs.oncommand = function(id,event){
	var str = winform.editCode.selText;
	if(!#str){
		str = winform.editCode.text 
		winform.show(0x6/*_SW_MINIMIZE*/)
	} 
	win.clip.write(str)	 
}

import fsys.dlg;
winform.popmenu = win.ui.popmenu(winform);//创建弹出菜单

winform.popmenu.add('生成Web窗体并复制...',function(id){
	str = getWebFormCode() 
	if(!str){
		winform.msgbox("代码不是合法的AAuto代码!")
		return;
	}
	win.clip.write(str)	
	
});
import process;
winform.popmenu.add('生成Web窗体并另存为...',function(id){
	var str = getWebFormCode();
	if(!str){
		winform.msgbox("代码不是合法的AAuto代码!")
		return;
	}
	var path = fsys.dlg.save("AAuto代码文件|*.aau||","生成AAuto代码并另存为......")
	if(path){
		string.save(path,str)
		process.explore_select(path)
	}
	
});
winform.popmenu.add()
winform.popmenu.add('复制选定 Ctrl+C',function(id){
	win.clip.write(winform.editCode.selText)	
	
});
winform.popmenu.add('粘贴 Ctrl+V',function(id){
	winform.editCode.selText = win.clip.read();
	
});
 
 
winform.editCode.wndproc = function(hwnd,message,wParam,lParam){ 
	if(message== 0x205/*_WM_RBUTTONUP 鼠标右键弹起，弹出菜单*/){
			var x,y = ::LOWORD(lParam), ::HIWORD(lParam)
			var l,t = winform.editCode.getPos()
			winform.popmenu.popup(l+x,t+y);//弹出菜单
	} elseif (message == 0x100/*_WM_KEYDOWN*/) {
		if (wParam == 0x74/*_VK_F5*/)
			winform.btnRun.oncommand();
	}
 
}
 
//绘图API
CreatePen			= Gdi32.api("CreatePen", "pointer(int nStyle, int nWidth, int nColor)");
Rectangle			= Gdi32.api("Rectangle", "int(pointer hDC, int nLeft, int nTop, int nRight, int nBottom)");
SetROP2				= Gdi32.api("SetROP2", "int(pointer hDC, int nMode)"); 
//选中对象高亮边框
 
flashRect = function(rc){ 
	var hDC = ::GetWindowDC(0);
	var screenCx,screenCy = win.getScreen()
	
	/** 防止溢出 Start **/
	rc.right =  math.min(rc.right,screenCx) ;
	rc.bottom =  math.min(rc.bottom,screenCy) 
	if (rc.left < 0)
		rc.left = 0;
	if (rc.top < 0)
		rc.top = 0; 
	/** 防止溢出 End **/ 
	
	var hPen = CreatePen(0x0/*_PS_SOLID*/, 3, 0);
	var hOldPen = ::SelectObject(hDC, hPen);
	var oldROP2 = SetROP2(hDC, 0xA/*_R2_NOTXORPEN*/);
	Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); 
	sleep(50)
	Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
	SetROP2(hDC, oldROP2);
	::SelectObject(hDC, hOldPen);
	::DeleteObject(hPen);
	::ReleaseDC(0, hDC);
}
 
tmFlashId = winform.addtimer(
	100/*毫秒*/,
	function(hwnd,msg,id,tick){//定时执行代码
		 if( winform.spyWb && winform.spying && winform.spyElement ){
		 	if( ! ( key.getStateX(0x1/*_VK_LBUTTON*/) || key.getStateX(0x11/*_VK_CTRL*/) )  ){
		 		if(winform.picturebox.wndproc)
		 			winform.picturebox.wndproc(winform.picturebox.hwnd,0x202/*_WM_LBUTTONUP*/,0,0);
		 		return;
		 	} 
		 	var e_x,e_y,e_cx,e_cy = winform.spyWb.getPos(winform.spyElement,true) 
 		 	flashRect( ::RECT(e_x+2,e_y+2,e_x+e_cx+2,e_y+e_cy+2) )  
 		 }
	}
);  

var html = /***
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<div id='test' style='font:12px/1.3em;text-align:right;margin-right:25px;'>
请将右上角的瞄准器图标用鼠标拖放到这里.<br />或者按住Ctrl键不放,然后移动鼠标到这里.<br /><br />
也可以将瞄准器图标拖动到外部浏览器网页上,以探测目标节点.<br /><br />
然后点击右下角“相关”按钮，可以打开该节点相关文档,<br />查看当前节点的属性、成员函数列表.<br /><br />
获取本程序全部源代码:<br /><a href="http://www.aau.cn/thread-411-1-1.html" target="_blank">http://www.aau.cn/thread-411-1-1.html</a>
<div>
</body>
</html>
***/ 
wb.write(html)
winform.editUrl.text = "http://"

var w = ::GetSystemMetrics(0x10/*_SM_CXFULLSCREEN*/); 
var h = ::GetSystemMetrics(0x11/*_SM_CYFULLSCREEN*/) ;
winform.setPos( w-760,h-535);
winform.show()
winform.spyWb = wb;
 
var doc = wb.waitDoc()
doc.attachEvent("onmousemove",onmousemove)

//进入消息循环
win.loopMessage();
return winform,wb;
