powershell コードを使用して、ウィンドウの位置を変更し (正常に動作します)、このウィンドウを「常に一番上」に配置しようとしました。
私のコードの下に見つけてください:
Import-Module C:/install/WASP/wasp.dll
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class SFW {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class allowFor {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AllowSetForegroundWindow(IntPtr hWnd);
}
"@
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class lockFor {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool LockSetForegroundWindow(IntPtr hWnd);
}
"@
do
{
Start-Sleep -m 3000
$allWindow = Select-Window Perso*
if($allWindow)
{
foreach ($currentWindow in $allWindow)
{
$positionWindow = WindowPosition $currentWindow
foreach ($currentPosition in $positionWindow)
{
#Loop on each windows
if ( $currentWindow.title -match "\([0-9]*\)#" )
{
# Retrieve windows ID
$id = $currentWindow.title.Substring($currentWindow.title.IndexOf("(")+1, $currentWindow.title.IndexOf(")")-$currentWindow.title.IndexOf("(")-1)
$allHUDWindow = Select-Window * | where {$_.Title -match "\($id\).*.txt"}
if($allHUDWindow)
{
foreach ($currentHUDWindow in $allHUDWindow)
{
$currentForgr = [Tricks]::GetForegroundWindow()
if ( ($currentForgr -match $currentWindow.Handle -or $currentForgr -match $currentHUDWindow.Handle) )
{
write-host "Pus currentHUDWindow in Front"
$hud = (get-process -Id $currentHUDWindow.ProcessId).MainWindowHandle
[allowFor]::AllowSetForegroundWindow(-1)
[SFW]::SetForegroundWindow($hud)
#Modification de la position
Set-WindowPosition -X ($currentPosition.x-10) -Y ($currentPosition.y-30) -WIDTH ($currentPosition.width+20) -HEIGHT ($currentPosition.height+30) -Window $currentHUDWindow
}
}
}
}
}
}
}
} while(1)
しかし :
[allowFor]::AllowSetForegroundWindow(-1)
[SFW]::SetForegroundWindow($hud)
False を返します。
ドキュメントから:
An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.
$currentHUDWindow を強制的に前面に移動させる方法を知っていますか? タスクバーボタンを点滅させるだけではありませんか?
ご協力いただきありがとうございます