@@ -58,29 +58,23 @@ private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam) {
5858
5959 private bool TransitionsForceDisabled {
6060 get {
61- int attributeValueSize = Marshal . SizeOf ( typeof ( int ) ) ;
62- IntPtr attributeValuePointer = Marshal . AllocHGlobal ( attributeValueSize ) ;
63-
64- try {
65- DwmGetWindowAttribute ( Handle , DWMWINDOWATTRIBUTE . DWMWA_TRANSITIONS_FORCEDISABLED , attributeValuePointer , ( uint ) attributeValueSize ) ;
66- return ( Marshal . ReadInt32 ( attributeValuePointer , 0 ) != 0 ) ? true : false ;
67- } finally {
68- Marshal . FreeHGlobal ( attributeValuePointer ) ;
61+ int attributeValue = 0 ;
62+
63+ int err = DwmGetWindowAttribute ( Handle , DWMWINDOWATTRIBUTE . DWMWA_TRANSITIONS_FORCEDISABLED , out attributeValue , ( uint ) Marshal . SizeOf ( typeof ( int ) ) ) ;
64+
65+ if ( err != S_OK ) {
66+ Marshal . ThrowExceptionForHR ( err ) ;
6967 }
68+ return ( attributeValue != 0 ) ? true : false ;
7069 }
7170
7271 set {
7372 int attributeValue = value ? 1 : 0 ;
73+
74+ int err = DwmSetWindowAttribute ( Handle , DWMWINDOWATTRIBUTE . DWMWA_TRANSITIONS_FORCEDISABLED , ref attributeValue , ( uint ) Marshal . SizeOf ( typeof ( int ) ) ) ;
7475
75- int attributeValueSize = Marshal . SizeOf ( attributeValue ) ;
76- IntPtr attributeValuePointer = Marshal . AllocHGlobal ( attributeValueSize ) ;
77-
78- try {
79- Marshal . WriteInt32 ( attributeValuePointer , 0 , attributeValue ) ;
80-
81- DwmSetWindowAttribute ( Handle , DWMWINDOWATTRIBUTE . DWMWA_TRANSITIONS_FORCEDISABLED , attributeValuePointer , ( uint ) attributeValueSize ) ;
82- } finally {
83- Marshal . FreeHGlobal ( attributeValuePointer ) ;
76+ if ( err != S_OK ) {
77+ Marshal . ThrowExceptionForHR ( err ) ;
8478 }
8579 }
8680 }
@@ -114,6 +108,7 @@ private bool ExitFullscreenLabelTimer {
114108 }
115109
116110 private bool fullscreen = false ;
111+ private bool fullscreenTransitionsForceDisabled = false ;
117112 private FormBorderStyle fullscreenFormBorderStyle = FormBorderStyle . Sizable ;
118113 private FormWindowState fullscreenWindowState = FormWindowState . Maximized ;
119114 private Point fullscreenLocation ;
@@ -152,9 +147,11 @@ public bool Fullscreen {
152147 closableWebBrowserSize = closableWebBrowser . Size ;
153148
154149 try {
150+ fullscreenTransitionsForceDisabled = TransitionsForceDisabled ;
155151 TransitionsForceDisabled = true ;
156152 } catch {
157- // Fail silently.
153+ // no Aero!
154+ fullscreenTransitionsForceDisabled = false ;
158155 }
159156
160157 // need to do this first to have an effect if starting maximized
@@ -181,13 +178,7 @@ public bool Fullscreen {
181178
182179 // commit by bringing the window to the front
183180 BringToFront ( ) ;
184-
185- try {
186- TransitionsForceDisabled = false ;
187- } catch {
188- // Fail silently.
189- }
190- } else {
181+ } else {
191182 // hide "Press F11 to exit fullscreen" label
192183 ExitFullscreenLabelTimer = false ;
193184
@@ -198,12 +189,6 @@ public bool Fullscreen {
198189 }
199190 }
200191
201- try {
202- TransitionsForceDisabled = true ;
203- } catch {
204- // Fail silently.
205- }
206-
207192 // need to do this first to reset the window to its former size
208193 FormBorderStyle = FormBorderStyle . Sizable ;
209194 // exit fullscreen
@@ -226,11 +211,11 @@ public bool Fullscreen {
226211
227212 // commit by bringing the window to the front
228213 BringToFront ( ) ;
229-
214+
230215 try {
231- TransitionsForceDisabled = false ;
216+ TransitionsForceDisabled = fullscreenTransitionsForceDisabled ;
232217 } catch {
233- // Fail silently.
218+ // no Aero!
234219 }
235220 }
236221 }
0 commit comments