@@ -148,4 +148,64 @@ public static Point TransformPixelsToDIP(Visual visual, double unitX, double uni
148148
149149 return new Point ( ( int ) ( matrix . M11 * unitX ) , ( int ) ( matrix . M22 * unitY ) ) ;
150150 }
151+
152+ #region Alt Tab
153+
154+ private static int SetWindowLong ( HWND hWnd , WINDOW_LONG_PTR_INDEX nIndex , int dwNewLong )
155+ {
156+ PInvoke . SetLastError ( WIN32_ERROR . NO_ERROR ) ; // Clear any existing error
157+
158+ var result = PInvoke . SetWindowLong ( hWnd , nIndex , dwNewLong ) ;
159+ if ( result == 0 && Marshal . GetLastPInvokeError ( ) != 0 )
160+ {
161+ throw new Win32Exception ( Marshal . GetLastPInvokeError ( ) ) ;
162+ }
163+
164+ return result ;
165+ }
166+
167+ /// <summary>
168+ /// Hide windows in the Alt+Tab window list
169+ /// </summary>
170+ /// <param name="window">To hide a window</param>
171+ public static void HideFromAltTab ( Window window )
172+ {
173+ var exStyle = GetCurrentWindowStyle ( window ) ;
174+
175+ // Add TOOLWINDOW style, remove APPWINDOW style
176+ var newExStyle = ( ( uint ) exStyle | ( uint ) WINDOW_EX_STYLE . WS_EX_TOOLWINDOW ) & ~ ( uint ) WINDOW_EX_STYLE . WS_EX_APPWINDOW ;
177+
178+ SetWindowLong ( new ( new WindowInteropHelper ( window ) . Handle ) , WINDOW_LONG_PTR_INDEX . GWL_EXSTYLE , ( int ) newExStyle ) ;
179+ }
180+
181+ /// <summary>
182+ /// Restore window display in the Alt+Tab window list.
183+ /// </summary>
184+ /// <param name="window">To restore the displayed window</param>
185+ public static void ShowInAltTab ( Window window )
186+ {
187+ var exStyle = GetCurrentWindowStyle ( window ) ;
188+
189+ // Remove the TOOLWINDOW style and add the APPWINDOW style.
190+ var newExStyle = ( ( uint ) exStyle & ~ ( uint ) WINDOW_EX_STYLE . WS_EX_TOOLWINDOW ) | ( uint ) WINDOW_EX_STYLE . WS_EX_APPWINDOW ;
191+
192+ SetWindowLong ( new ( new WindowInteropHelper ( window ) . Handle ) , WINDOW_LONG_PTR_INDEX . GWL_EXSTYLE , ( int ) newExStyle ) ;
193+ }
194+
195+ /// <summary>
196+ /// To obtain the current overridden style of a window.
197+ /// </summary>
198+ /// <param name="window">To obtain the style dialog window</param>
199+ /// <returns>current extension style value</returns>
200+ private static int GetCurrentWindowStyle ( Window window )
201+ {
202+ var style = PInvoke . GetWindowLong ( new ( new WindowInteropHelper ( window ) . Handle ) , WINDOW_LONG_PTR_INDEX . GWL_EXSTYLE ) ;
203+ if ( style == 0 && Marshal . GetLastPInvokeError ( ) != 0 )
204+ {
205+ throw new Win32Exception ( Marshal . GetLastPInvokeError ( ) ) ;
206+ }
207+ return style ;
208+ }
209+
210+ #endregion
151211}
0 commit comments