IEをWSHなど、外部から操作するときは、
Set ie=CreateObject("InternetExplorer.Application")
ie.Left=ie.Left
ie.Top=ie.Top
ie.Width=ie.Width
ie.Height=ie.Height
で、ウィンドウの位置やサイズを参照、変更することができます。
しかし、HTAやHTMLでは、内部のスクリプトから、
window.moveTo
window.resizeTo
で、ウィンドウの位置やサイズを変更することはできますが、
ウィンドウの位置やサイズを取得する機能がありません。
なんで、こういう非対称な機能設計にするのか、と理解に苦しみます。
ウィンドウの位置については、
window.screenLeft
window.screenTop
でクライアント領域の位置は取れますが、
window.moveToの指定位置とは異なります。
一次方程式で書くと、
window.screenLeft=ie.Left+x
window.screenTop=ie.Top+y
このままでは解けないので、moveToで条件を変えて連立方程式を作ります。
screenLeft1=Left1+x
screenTop1=Top1+y
moveTo Left2,Top2
screenLeft2=Left2+x
screenTop2=Top2+y
これを変形すると、
x=screenLeft2-Left2
y=screenTop2-Top2
Left1=screenLeft1-x=screenLeft1-screenLeft2+Left2
Top1=screenTop1-y=screenTop1-screenTop2+Top2
元の位置が分かるので、戻します。
moveTo Left1,Top1
ウィンドウのサイズについても、同様に、
一次方程式で書くと、
window.offsetWidth=ie.Width-x
window.offsetHeight=ie.Height-y
連立方程式は、
offsetWidth1=Width1-x
offsetHeight1=Height1-y
resizeTo Width2,Height2
offsetWidth2=Width2-x
offsetHeight2=Height2-y
解くと、
x=Width2-offsetWidth2
y=Height2-offsetHeight2
Width1=offsetWidth1+x=offsetWidth1+Width2-offsetWidth2
Height1=offsetHeight1+y=offsetHeight1+Height2-offsetHeight2
元のサイズに戻します。
resizeTo Width1,Height1
こうやって代替関数が作れます。
Sub GetPosition(Left1,Top1)
Dim screenLeft1
Dim screenTop1
Dim Left2
Dim Top2
screenLeft1=window.screenLeft
screenTop1=window.screenTop
Left2=screenLeft1
Top2=screenTop1
moveTo Left2,Top2
Left1=screenLeft1+Left2-window.screenleft
Top1=screenTop1+Top2-window.screenTop
moveTo Left1,Top1
End Sub
Sub GetSize(Width1,Height1)
Dim offsetWidth1
Dim offsetHeight1
Dim Width2
Dim Height2
offsetWidth1=document.body.offsetWidth
offsetHeight1=document.body.offsetHeight
Width2=offsetWidth1
If offsetHeight1>270 Then Height2=offsetHeight1 Else Height2=270
resizeTo Width2,Height2
Width1=offsetWidth1+Width2-document.body.offsetWidth
Height1=offsetheight1+Height2-document.body.offsetHeight
resizeTo Width1,Height1
End Sub
HTA、HTML(IE)で使えます。
サイズの取得については閾値があって、小さい領域では、
サイズが正確に取れなかったり、サイズが変化したまま戻らなかったりします。
なので、HTML(IE)の場合は、以下の方法がよいかも知れません。
<object id=ShellWindows classid=clsid:9BA05972-F6A8-11CF-A442-00A0C90A8F39></object>
<script language=vbscript>
Dim ie
For Each ie In ShellWindows
If TypeName(ie.Document)<>"HTMLDocument" Then
ElseIf ie.Document.parentWindow Is window Then
Exit For
End If
Next
MsgBox Join(Array(ie.Left,ie.Top,ie.Width,ie.Height))
</script>
HTML内から自身のIEを見つけて、ie.Left/ie.Top/ie.Width/ie.Heightで、
ウィンドウの位置やサイズを変更、参照することができます。
なので、HTAでは使えません。
また、オブジェクトを使用するので、セキュリティレベルを前述の方法より下げる必要があります。
Windows XP SP2(IE6.0/WSH5.6)でのみ確認しています。
Windows 2000でも、動くと思いますが、確認できません。