Center non-modal window on displayHi, I am trying to find the fastest way to move a window to the center of the users display.
Modal windows automatically are centered on the screen, so I know that JMP is somehow able to tell where to put a window, but I have only found some relatively slow workarounds to doing this with non-modal windows. Below is the jsl script I am currently using to determine the screen size and center a new window.
Is there a faster way? Thanks!
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);ScriptingWindowsRe: Center non-modal window on displayYour method is the method I normally use.
Re: Center non-modal window on displayIn my experience the <<GET window="" size=""></GET> method is not reliable. The issue is that <<GET window="" size=""></GET> does not return physical pixels but logical pixels (affected by Windows display scaling), while <<MOVE window=""> uses physical pixels. Also, JMP in general and <CODE class=" language-jsl"><<GET window="" size=""></GET> in specific does not update when the Windows display scaling changes (if a user starts JMP on a laptop and later hooks up a monitor, for instance).
I run the following PowerShell script from JMP to get the actual screen resolution and use this info to place windows as appropriate (you'll have to launch powershell with -ExecutionPolicy Bypass:
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
Re: Center non-modal window on displayThis is the kind of hocus pocus I was looking for haha. Thanks Jim and Jordan! I will try out both options and see which is faster and/or more reliable