Advertisement
Guest User

FullScreen

a guest
Mar 14th, 2012
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # settings, 0 = use default
  2. [string] $targetimagename = "client.exe"
  3. [int] $targetwidth = 0
  4. [int] $targetheight = 0
  5. [int] $targetdisplay = 0
  6. [int] $borderfix = 0
  7.  
  8. # load System.Windows
  9. $void = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  10.  
  11. # import c#
  12. Add-Type -Language CSharpVersion3 @"
  13. using System;
  14. using System.Runtime.InteropServices;
  15.  
  16. public class WindowUtil
  17. {
  18.    [StructLayout(LayoutKind.Sequential)]
  19.    public struct RECT
  20.    {
  21.        public int Left;
  22.        public int Top;
  23.        public int Right;
  24.        public int Bottom;
  25.    }
  26.  
  27.    [DllImport("user32.dll")]
  28.    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  29.  
  30.    [DllImport("user32.dll")]
  31.    public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
  32.  
  33.    [DllImport("user32.dll")]
  34.    public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
  35.    
  36.    [DllImport("user32.dll")]
  37.    public static extern bool SetWindowPos(IntPtr hWnd,
  38.        int hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
  39.        
  40.    public static void MaximizeWindow(IntPtr hWnd, int w, int h, int fix)
  41.    {
  42.        RECT inner, outer;
  43.        
  44.        ShowWindow(hWnd, 1 /* restore and activate */);
  45.        GetClientRect(hWnd, out inner);
  46.        GetWindowRect(hWnd, out outer);
  47.        
  48.        int border = (outer.Right - outer.Left) - (inner.Right - inner.Left);
  49.        int titlebar = (outer.Bottom - outer.Top) - (inner.Bottom - inner.Top) - border;
  50.        border = border / 2 - fix;
  51.        
  52.        SetWindowPos(hWnd, 1/*HWND_TOPMOST*/,
  53.           -border, -border - titlebar, w + border * 2, h + titlebar + border * 2,
  54.           0x0400/*SWP_NOSENDCHANGING*/);
  55.    }
  56. }
  57. "@
  58.  
  59. # set screen size
  60. Function GetScreenSize
  61. {
  62.     $screens = [System.Windows.Forms.Screen]::AllScreens
  63.     if (($targetdisplay -le 0) -or ($targetdisplay -gt $screens.Count)) {
  64.         $screen = $screens[0]
  65.     } else {
  66.         $screen = $screens[$targetdisplay - 1];
  67.     }
  68.     #"Screen Resolution: {0}x{1}" -f $screen.Bounds.Width, $screen.Bounds.Height
  69.     if ($targetwidth -eq 0)  {
  70.         $global:targetwidth = $screen.Bounds.Width
  71.     }
  72.     if ($targetheight -eq 0) {
  73.         $global:targetheight = $screen.Bounds.Height
  74.     }
  75. }
  76.  
  77. GetScreenSize
  78. [int] $found = 0
  79. get-process | foreach-object -process   {
  80.     if ($_.MainModule.ModuleName -eq $targetimagename)  {
  81.         [WindowUtil]::MaximizeWindow($_.MainWindowHandle, $targetwidth, $targetheight, $borderfix)
  82.         $found++
  83.     }
  84. }
  85. "Found {0} matches" -f $found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement