FunWithElectronics.com
          - Collection of Information for those with Electronics as a Hobby
Up one level (Programming)

Powershell





Add-Type @"
using System;
using System.Runtime.InteropServices;

public class Tricks {
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetForegroundWindow(IntPtr hWnd);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
}

     public struct RECT
     {
         public int Left; // x position of upper-left corner
         public int Top; // y position of upper-left corner
         public int Right; // x position of lower-right corner
         public int Bottom; // y position of lower-right corner
     }
"@


$h = (Get-Process vnc-P4_4_3-x86_win32_viewer).MainWindowHandle
[void] [Tricks]::SetForegroundWindow($h)
$rcWindow = New-Object RECT

[Tricks]::GetWindowRect($h,[ref]$rcWindow)
$rcWindow
[void] [Tricks]::ShowWindowAsync($h, 3)
[Tricks]::MoveWindow($h,-11,-32,3860,1240,$true)

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"@

$sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32

$h = (Get-Process firefox).MainWindowHandle
[Win32.NativeMethods]::ShowWindowAsync($h, 3)
[void] [Tricks]::SetForegroundWindow($h)



Add a comment:

Fill in number
Name:
Title:
Text:
 


Privacy | Contact