Pour ceux qui sont familiers avec PowerShell, essayez ceci :
- Copiez et collez le code ci-dessous dans une session PowerShell ISE.
- Hit Run
- Appuyez sur ALT+TAB/quelque chose pour rendre la fenêtre hors écran active.
- Attendez quelques instants (5 secondes après avoir appuyé sur la touche RUN du script).
- La fenêtre devrait maintenant apparaître.
Si la fenêtre est une fenêtre principale, elle sera déplacée dans le coin supérieur gauche de l'écran.
Si la fenêtre est une fenêtre enfant d'un autre programme, son coin supérieur gauche sera aligné sur le coin supérieur gauche de sa fenêtre parent.
Add-Type @"
using System;
using System.Runtime.InteropServices;
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx
public struct RECT
{
public long left;
public long top;
public long right;
public long bottom;
}
public class User32WinApi
{
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633505(v=vs.85).aspx
/*
Gets the handle of the in-focus window
NB: In some scenarios this can be NULL; so code needed to handle such an event
*/
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633503(v=vs.85).aspx
/*
top & left are always 0 (i.e. since the rectangle is relative to the window itself)
bottom & right equal the windows hieght and width, respectively.
*/
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms633534(v=vs.85).aspx
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
}
"@
$repaint = $true
$windowSize = New-Object RECT
"Quick; get the window you're after in focus; you have 5 seconds..."
Start-Sleep -Seconds 5 #allow 5 seconds for the user to get the window they're after in focus (e.g. using ALT+TAB / whatever)
$activeWindow = [User32WinApi]::GetForegroundWindow()
if ($activeWindow) {
if([User32WinApi]::GetClientRect($activeWindow, [ref]$windowSize)) {
if ([User32WinApi]::MoveWindow($activeWindow, 0, 0, $windowSize.right, $windowSize.bottom, $repaint)) {
"Window moved successfully (hope you agree!)"
} else {
Write-Warning "Failed to move the active window"
}
} else {
Write-Warning "Failed to get size of the active window"
}
} else {
Write-Warning "No active window found"
}
Le code original est ici : https://gist.githubusercontent.com/JohnLBevan/1593bbb860c2d2af436a1c9414e8adfa/
4 votes
C'est toujours un problème dans Windows 10 ! J'ai 3 moniteurs et je n'en utilise qu'un "ici et là"... quand je le fais, puis que j'arrête de l'utiliser, certains programmes ouverts s'ouvrent par défaut sur celui-ci. Je dois faire le win+flèche gauche pour finalement le faire revenir sur le moniteur principal.
4 votes
Toujours un problème sept ans plus tard...
0 votes
Duplicata possible de superuser.com/questions/1206086/
0 votes
Winlister est le meilleur.. J'ai essayé les autres astuces avant, mais celle-ci fonctionne tout le temps. alt-space, etc. ne fonctionne que sur certains Windows.