Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Helper functions for gaining access to Win32 API
- ###########################################################################################
- $script:nativeMethods = @();
- function Register-NativeMethod([string]$dll, [string]$methodSignature)
- {
- $script:nativeMethods += [PSCustomObject]@{ Dll = $dll; Signature = $methodSignature; }
- }
- function Add-NativeMethods()
- {
- $nativeMethodsCode = $script:nativeMethods | % { "
- [DllImport(`"$($_.Dll)`")]
- public static extern $($_.Signature);
- " }
- Add-Type @"
- using System;
- using System.Runtime.InteropServices;
- public class NativeMethods {
- $nativeMethodsCode
- }
- "@
- }
- ###########################################################################################
- # Add your Win32 API here:
- ###########################################################################################
- Register-NativeMethod "user32.dll" "bool SetForegroundWindow(IntPtr hWnd)"
- Register-NativeMethod "user32.dll" "bool ShowWindow(IntPtr hWnd, int nCmdShow)"
- Register-NativeMethod "user32.dll" "bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint)"
- Register-NativeMethod "user32.dll" "bool AnimateWindow(IntPtr hwnd, UInt32 dwTime, UInt32 dwFlags)"
- Register-NativeMethod "user32.dll" "IntPtr FindWindow(IntPtr ZeroOnly, string lpWindowName)"
- Register-NativeMethod "user32.dll" "void keybd_event(Byte bVk, Byte bScan, UInt32 dwFlags, UInt32 dwExtraInfo)"
- Register-NativeMethod "user32.dll" "bool InvalidateRect(IntPtr hWnd, IntPtr ZeroOnly, bool bErase)"
- Register-NativeMethod "user32.dll" "UInt16 TileWindows(IntPtr ZeroOnly, int wHow, IntPtr lpRect, int cKids, IntPtr[] lpKids)"
- Register-NativeMethod "dwmapi.dll" "void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind)"
- ###########################################################################################
- # Build class and registers them:
- Add-NativeMethods
- $application = New-Object -com shell.application
- [DllImport("dwmapi.dll")]
- static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind);
Advertisement
Add Comment
Please, Sign In to add comment