使用 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)
还我假。
从文档中:
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 向前移动吗?而且不只闪烁任务栏按钮?
谢谢你的帮助