@@ -66,6 +66,43 @@ public static class ReleaseSmokeNativeMethods
6666 public int Bottom;
6767 }
6868
69+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
70+ public struct DEVMODE
71+ {
72+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
73+ public string dmDeviceName;
74+ public short dmSpecVersion;
75+ public short dmDriverVersion;
76+ public short dmSize;
77+ public short dmDriverExtra;
78+ public int dmFields;
79+ public int dmPositionX;
80+ public int dmPositionY;
81+ public int dmDisplayOrientation;
82+ public int dmDisplayFixedOutput;
83+ public short dmColor;
84+ public short dmDuplex;
85+ public short dmYResolution;
86+ public short dmTTOption;
87+ public short dmCollate;
88+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
89+ public string dmFormName;
90+ public short dmLogPixels;
91+ public int dmBitsPerPel;
92+ public int dmPelsWidth;
93+ public int dmPelsHeight;
94+ public int dmDisplayFlags;
95+ public int dmDisplayFrequency;
96+ public int dmICMMethod;
97+ public int dmICMIntent;
98+ public int dmMediaType;
99+ public int dmDitherType;
100+ public int dmReserved1;
101+ public int dmReserved2;
102+ public int dmPanningWidth;
103+ public int dmPanningHeight;
104+ }
105+
69106 [DllImport("user32.dll")]
70107 public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
71108
@@ -92,6 +129,12 @@ public static class ReleaseSmokeNativeMethods
92129
93130 [DllImport("gdi32.dll")]
94131 public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
132+
133+ [DllImport("user32.dll", CharSet = CharSet.Ansi)]
134+ public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
135+
136+ [DllImport("user32.dll", CharSet = CharSet.Ansi)]
137+ public static extern int ChangeDisplaySettings(ref DEVMODE devMode, int flags);
95138}
96139'@
97140 }
@@ -102,6 +145,35 @@ public static class ReleaseSmokeNativeMethods
102145 Add-Type - AssemblyName System.Drawing
103146}
104147
148+ function Set-InteractiveDisplayResolution {
149+ param (
150+ [Parameter (Mandatory )]
151+ [int ] $Width ,
152+
153+ [Parameter (Mandatory )]
154+ [int ] $Height
155+ )
156+
157+ Initialize-ScreenshotSupport
158+
159+ $currentSettings = -1
160+ $devMode = New-Object ' ReleaseSmokeNativeMethods+DEVMODE'
161+ $devMode.dmSize = [System.Runtime.InteropServices.Marshal ]::SizeOf([type ] ' ReleaseSmokeNativeMethods+DEVMODE' )
162+
163+ if (-not [ReleaseSmokeNativeMethods ]::EnumDisplaySettings($null , $currentSettings , [ref ] $devMode )) {
164+ throw ' EnumDisplaySettings failed while reading the current RDP display mode.'
165+ }
166+
167+ $devMode.dmPelsWidth = $Width
168+ $devMode.dmPelsHeight = $Height
169+ $devMode.dmFields = 0x180000
170+
171+ $result = [ReleaseSmokeNativeMethods ]::ChangeDisplaySettings([ref ] $devMode , 0 )
172+ if ($result -ne 0 ) {
173+ throw " ChangeDisplaySettings failed while setting ${Width} x${Height} ; result=$result ."
174+ }
175+ }
176+
105177function Get-PhysicalDesktopBounds {
106178 Initialize-ScreenshotSupport
107179
@@ -140,6 +212,22 @@ function Get-PhysicalDesktopBounds {
140212 }
141213}
142214
215+ function Get-DisplayMetrics {
216+ Initialize-ScreenshotSupport
217+
218+ $physicalBounds = Get-PhysicalDesktopBounds
219+ $virtualBounds = [System.Windows.Forms.SystemInformation ]::VirtualScreen
220+
221+ [pscustomobject ]@ {
222+ PhysicalWidth = $physicalBounds.Width
223+ PhysicalHeight = $physicalBounds.Height
224+ VirtualWidth = $virtualBounds.Width
225+ VirtualHeight = $virtualBounds.Height
226+ VirtualLeft = $virtualBounds.Left
227+ VirtualTop = $virtualBounds.Top
228+ }
229+ }
230+
143231function Wait-UniGetUIWindow {
144232 param (
145233 [Parameter (Mandatory )]
@@ -269,6 +357,24 @@ function Save-WindowScreenshot {
269357}
270358
271359New-Item - Path $ArtifactsDir - ItemType Directory - Force | Out-Null
360+ $targetDesktopWidth = 1920
361+ $targetDesktopHeight = 1080
362+ $displayBefore = Get-DisplayMetrics
363+ Set-InteractiveDisplayResolution - Width $targetDesktopWidth - Height $targetDesktopHeight
364+ Start-Sleep - Seconds 3
365+ $displayAfter = Get-DisplayMetrics
366+
367+ if ($displayAfter.PhysicalWidth -ne $targetDesktopWidth -or $displayAfter.PhysicalHeight -ne $targetDesktopHeight ) {
368+ throw " RDP desktop is $ ( $displayAfter.PhysicalWidth ) x$ ( $displayAfter.PhysicalHeight ) , expected ${targetDesktopWidth} x${targetDesktopHeight} ."
369+ }
370+
371+ [pscustomobject ]@ {
372+ RequestedWidth = $targetDesktopWidth
373+ RequestedHeight = $targetDesktopHeight
374+ Before = $displayBefore
375+ After = $displayAfter
376+ } | ConvertTo-Json - Depth 6 | Set-Content - Path (Join-Path $ArtifactsDir ' display-metrics.json' ) - Encoding utf8NoBOM
377+
272378$downloadsDir = Join-Path $ArtifactsDir ' downloads'
273379New-Item - Path $downloadsDir - ItemType Directory - Force | Out-Null
274380
0 commit comments