顯示中心非模態窗口您好,我正在嘗試找到將窗口移動到用戶顯示中心的最快方法。
模態窗口自動在屏幕上居中,因此我知道 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 ) );
