we_window.ps1 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # we_window.ps1 - run in the VM through winvm.sh run: hides WE's UI pop-up and prints the wallpaper window's client
  2. # rectangle in screen pixels ("x y w h"), what decode.py style frame readers need
  3. Add-Type @'
  4. using System;
  5. using System.Text;
  6. using System.Runtime.InteropServices;
  7. public static class W {
  8. public delegate bool EnumProc (IntPtr h, IntPtr p);
  9. [DllImport ("user32.dll")] public static extern bool EnumWindows (EnumProc f, IntPtr p);
  10. [DllImport ("user32.dll")] public static extern int GetWindowText (IntPtr h, StringBuilder s, int n);
  11. [DllImport ("user32.dll")] public static extern bool IsWindowVisible (IntPtr h);
  12. [DllImport ("user32.dll")] public static extern bool ShowWindow (IntPtr h, int cmd);
  13. [DllImport ("user32.dll")] public static extern bool GetClientRect (IntPtr h, out RECT r);
  14. [DllImport ("user32.dll")] public static extern bool ClientToScreen (IntPtr h, ref POINT p);
  15. [StructLayout (LayoutKind.Sequential)] public struct RECT { public int L, T, R, B; }
  16. [StructLayout (LayoutKind.Sequential)] public struct POINT { public int X, Y; }
  17. }
  18. '@
  19. $found = New-Object System.Collections.ArrayList
  20. $cb = [W+EnumProc] {
  21. param($h, $p)
  22. $s = New-Object System.Text.StringBuilder 256
  23. [W]::GetWindowText($h, $s, 256) | Out-Null
  24. if ([W]::IsWindowVisible($h)) { $found.Add(@($h, $s.ToString())) | Out-Null }
  25. return $true
  26. }
  27. [W]::EnumWindows($cb, [IntPtr]::Zero) | Out-Null
  28. foreach ($w in $found) {
  29. if ($w[1] -eq 'Wallpaper UI') { [W]::ShowWindow($w[0], 0) | Out-Null; 'hid Wallpaper UI' }
  30. }
  31. foreach ($w in $found) {
  32. if ($w[1] -eq 'Wallpaper Pop-out') {
  33. $r = New-Object W+RECT
  34. [W]::GetClientRect($w[0], [ref] $r) | Out-Null
  35. $pt = New-Object W+POINT
  36. [W]::ClientToScreen($w[0], [ref] $pt) | Out-Null
  37. "client $($pt.X) $($pt.Y) $($r.R - $r.L) $($r.B - $r.T)"
  38. }
  39. }