「ソースの表示」ウィンドウがIEの後ろに隠れる。(その3)
PowerShellスクリプトで新規の「ソースの表示」ウィンドウを監視して、3秒以内に隠れたら前に出します。
Excelがない環境もあるので、PowerShellを使います。
view-source-focus.ps1
Add-Type -Language VisualBasic @"
Public Class Shell32
Declare Auto Function FindWindow Lib "user32" (lpClassName As String, lpWindowName As Integer) As Integer
Declare Auto Function GetWindowText Lib "user32" (hwnd As Integer, lpString As System.Text.StringBuilder, cch As Integer) As Integer
Declare Function SetForegroundWindow Lib "user32" (hwnd As Integer) As Integer
End Class
"@
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic")
$dic=@{}
while($true){
$hwnd = [Shell32]::FindWindow([ref]"HTMLSOURCEVIEW",0)
$hwnd
if($hwnd -eq 0){
foreach($hwnd in $dic.Keys){
"$hwnd End " + $dic.Item($hwnd)
}
$dic.Clear()
}elseif(! $dic.Contains($hwnd)){
$lpString = new-object System.Text.StringBuilder 128
$nCount = [Shell32]::GetWindowText($hwnd,$lpString,$lpString.Capacity)
$dic.Add($hwnd,$lpString.ToString())
"$hwnd" + " New " + $lpString.ToString()
for($k = 0; $k -lt 3; $k++){
$r = [Shell32]::SetForegroundWindow($hwnd)
"$r"
if($r -eq 0){
$nCount = [Shell32]::GetWindowText($hwnd,$lpString,$lpString.Capacity)
if($lpString.ToString() -ne $dic.Item($hwnd)){break;}
[Windows.Forms.SendKeys]::SendWait("%{tab}")
[Microsoft.VisualBasic.Interaction]::AppActivate($lpString.ToString())
}
start-sleep -m 1000
}
}
$keys = @()
foreach($hwnd in $dic.Keys){
$lpString = new-object System.Text.StringBuilder 128
$nCount = [Shell32]::GetWindowText($hwnd,$lpString,$lpString.Capacity)
if($lpString.ToString() -ne $dic.Item($hwnd)){
"$hwnd End " + $dic.Item($hwnd)
$keys +=$hwnd
}
}
foreach($hwnd in $keys){
$dic.Remove($hwnd)
}
start-sleep -m 1000
}
監視状況をコンソールに表示します。監視スクリプトはCTRL+Cで終了します。
« 「ソースの表示」ウィンドウがIEの後ろに隠れる。(その2) | トップページ | about:home アドレスバーからホームページに移動する。 »