我正在编写一个批处理脚本来打开一系列 MessageBox 和 InputBox 窗口。该程序在首次启动时运行良好,并且用户能够与窗口交互,但是如果他们单击任何其他程序,则会将它们带到前台并基本上隐藏消息/输入框。这是两个框的示例,如何在使用程序时将它们始终保持在其他窗口的顶部?
powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"`r`nEnter the unique component number:`r`n\", 'Component Number')}" > %TEMP%\uniqueno1.tmp
set /p UniqueNo1=<%TEMP%\uniqueno1.tmp
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show(\"Unique Component Number %UniqueNo1%`r`n`r`n Click OK on this window to continue\", 'Component Number',0)>nul
试试这个:
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show(\"Unique Component Number %UniqueNo1%`r`n`r`n Click OK on this window to continue\", 'Component Number',0,0,0,131072)>nul
标志枚举 131072 代表 DefaultDesktopOnly。
替代方案可能是
(new-object System.Windows.Window -Property @{TopMost = true})
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }),\"Unique Component Number %UniqueNo1%`r`n`r`n Click OK on this window to continue\", 'Component Number',0)>nul
但这对我不起作用。也许它应该以其他方式使用,不知道。