#include <WindowsConstants.au3>
#include <IE.au3>
Opt("GUIResizeMode", 1)
Global $oIE = _IECreateEmbedded()
$gui = GUICreate("测试", 700, 600, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX))
$obj = GUICtrlCreateObj($oIE, 0, 0, 700, 600)
_IENavigate($oIE, "http://www.baidu.com/")
Local $op = _IEGetObjById($oIE,"nv")
Local $of = _IEGetObjById($oIE, "su")
;获取元素文本矩型
Local $pRect = $op.getBoundingClientRect()
Local $fRect = $of.getBoundingClientRect()
;计算位置
Local $left = -$pRect.left
Local $top = -$pRect.top
Local $width = $pRect.right-$pRect.left
Local $height = $fRect.bottom
_HideScroll($oIE) ;隐藏滚动条
;调整窗口和控件位置
Local $wPos = WinGetPos($gui)
Local $h = $wPos[3]-600
WinMove($gui,"",Default,Default,$width,($fRect.bottom-$pRect.top)+$h)
GUICtrlSetPos($obj,$left,$top,$width,$height)
GUISetState() ;显示窗口
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
While 1
Sleep(100)
WEnd
Func WM_SYSCOMMAND($hWnd, $sMsg, $sWParam, $slParam)
Switch $sWParam
Case 61536 ;$SC_CLOSE
Exit
EndSwitch
EndFunc ;==>WM_SYSCOMMAND
Func _HideScroll($Temp_Object)
Local $hText = 'var temp_h1 = document.body.clientHeight;'& _
'var temp_h2 = document.documentElement.clientHeight;'& _
'var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false;'& _
'var htmlbody = isXhtml?document.documentElement:document.body;'& _
'htmlbody.style.overflow = "hidden";'
$Temp_Object.document.parentwindow.execscript($hText,"javascript")
EndFunc
|