显示中心非模态窗口您好,我正在尝试找到将窗口移动到用户显示中心的最快方法。
模态窗口自动在屏幕上居中,因此我知道 JMP 能够以某种方式告诉在哪里放置窗口,但我只找到了一些相对较慢的解决方法来使用非模态窗口执行此操作。 下面是我当前用于确定屏幕尺寸并将新窗口居中的 jsl 脚本。
有更快的方法吗? 谢谢!
win2 = NewWindow("Test Window");
winSize = win2 << GetWindowSize();
win2 << ShowWindow(0);
testwin = NewWindow("test", << ShowWindow(0));
testwin << Maximize Window(1);
dispsize = testwin << Get Window Size;
testwin << CloseWindow();
win2 << MoveWindow(dispsize[1]/2 - winsize[1]/2, dispsize[2]/2 - winsize[2]/2);
win2 << ShowWindow(1);自动化和脚本编写视窗回复:显示中心非模态窗口这就是我一直在寻找的那种骗术哈哈。 谢谢吉姆和乔丹! 我将尝试这两个选项,看看哪个更快和/或更可靠
回复:显示中心非模态窗口根据我的经验<<获取窗口大小方法不可靠。问题是<<获取窗口大小不返回物理像素,而是返回逻辑像素(受 Windows 显示缩放影响),而<<移动窗口(x,y)使用物理像素。此外,JMP 一般而言和<<获取窗口大小具体来说,当 Windows 显示缩放比例发生变化时(例如,如果用户在笔记本电脑上启动 JMP,然后连接显示器),则不会更新。
我从 JMP 运行以下 PowerShell 脚本来获取实际的屏幕分辨率,并使用此信息来适当放置窗口(您必须使用以下命令启动 powershell -执行策略绕过:
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class PInvoke {
[DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("gdi32.dll")] public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
}
"@
$hdc = [PInvoke]::GetDC([IntPtr]::Zero)
[PInvoke]::GetDeviceCaps($hdc, 118) # width
[PInvoke]::GetDeviceCaps($hdc, 117) # height
回复:显示中心非模态窗口你的方法是我平时用的方法。
回复:将非模态窗口置于显示屏中央你好,
非常感谢您的提示!虽然已经过去很多年了,但这个问题仍然适用:如何使用“运行程序”将这些信息(关于屏幕尺寸)从 PowerShell 传输到 JMP?
回复:将非模态窗口置于显示屏中央您可以使用文本作为读取函数()并使用words()拆分字符串
powershell_code ="
Add-Type -AssemblyName System.Windows.Forms
$primary = [System.Windows.Forms.Screen]::PrimaryScreen
Write-Output $primary.Bounds.Width
Write-Output $primary.Bounds.Height
";
result = Run Program(
Executable( "powershell.exe" ),
Options( {"-Command", powershell_code} ),
Read Function( "text" )
);
{w, h} = Transform Each( {str}, Words( result, "\!n\!r" ), Num( str ) );
