设置IE大小和位置


#region Global Variable
$Script:HandleNumber = 0
#endregion Global Variable

#region Set IE Position And Window Size

CLS
Function SetIEPositionSimple($ProcessName,[int]$X,[int]$Y,[int]$Width,[int]$Height)
{
 Add-Type @"
              using System;
              using System.Runtime.InteropServices;
              public class Window {
                [DllImport("user32.dll")]
                [return: MarshalAs(UnmanagedType.Bool)]
                public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

                [DllImport("User32.dll")]
                public extern static bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
              }
              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
              }
"@

$Handle =  (Get-Process -Name $ProcessName |? {$_.MainWindowTitle -ne ''}).MainWindowHandle 
$Global:HandleNumber = $Handle
[Window]::MoveWindow($Handle, $X, $Y, $Width, $Height,$True) #Move the Window
    
}
#endregion Set IE Position And Window Size

#region Move IE (Customize Area)
#################################Move IE##########################################
SetIEPositionSimple -ProcessName 'iexplore'   0  0  1520  720
#################################Move IE##########################################
#endregion Move IE (Customize Area)

#region Set Focus On IE
###################################Set Focus on IE##############################
$setFore = @'
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
'@

$SetForeWindow=add-type -memberdefinition $setfore -name setforeground -passthru


$setforewindow::setforegroundwindow($Global:HandleNumber)
###################################Set Focus on IE##############################
#endregion Set Focus On IE

#region Send Key to IE
################################Send Key on the focused IE##################################
CLS
add-type -AssemblyName System.Windows.Forms
start-sleep -Milliseconds 500
$TextString = "{F11}"
[System.Windows.Forms.SendKeys]::SendWait($TextString)
################################Send Key on the focused IE##################################
#endregion Send Key to IE
×用微信扫描并分享
本文链接: https://www.pstips.net/%e8%ae%be%e7%bd%aeie%e5%a4%a7%e5%b0%8f%e5%92%8c%e4%bd%8d%e7%bd%ae.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

电子邮件地址不会被公开。 必填项已用*标注