@@ -148,4 +148,79 @@ public static Point TransformPixelsToDIP(Visual visual, double unitX, double uni
148
148
149
149
return new Point ( ( int ) ( matrix . M11 * unitX ) , ( int ) ( matrix . M22 * unitY ) ) ;
150
150
}
151
+
152
+ #region Alt Tab
153
+
154
+ private const int GWL_EXSTYLE = - 20 ;
155
+ private const int WS_EX_TOOLWINDOW = 0x00000080 ;
156
+ private const int WS_EX_APPWINDOW = 0x00040000 ;
157
+
158
+ [ DllImport ( "user32.dll" ) ]
159
+ private static extern IntPtr GetWindowLong ( IntPtr hWnd , int nIndex ) ;
160
+
161
+ [ DllImport ( "user32.dll" , EntryPoint = "SetWindowLongPtr" , SetLastError = true ) ]
162
+ private static extern IntPtr IntSetWindowLongPtr ( IntPtr hWnd , int nIndex , IntPtr dwNewLong ) ;
163
+
164
+ [ DllImport ( "user32.dll" , EntryPoint = "SetWindowLong" , SetLastError = true ) ]
165
+ private static extern int IntSetWindowLong ( IntPtr hWnd , int nIndex , int dwNewLong ) ;
166
+
167
+ [ DllImport ( "kernel32.dll" , EntryPoint = "SetLastError" ) ]
168
+ private static extern void SetLastError ( int dwErrorCode ) ;
169
+
170
+ private static IntPtr SetWindowLong ( IntPtr hWnd , int nIndex , IntPtr dwNewLong )
171
+ {
172
+ SetLastError ( 0 ) ; // Clear any existing error
173
+
174
+ if ( IntPtr . Size == 4 ) return new IntPtr ( IntSetWindowLong ( hWnd , nIndex , IntPtrToInt32 ( dwNewLong ) ) ) ;
175
+
176
+ return IntSetWindowLongPtr ( hWnd , nIndex , dwNewLong ) ;
177
+ }
178
+
179
+ private static int IntPtrToInt32 ( IntPtr intPtr )
180
+ {
181
+ return unchecked ( ( int ) intPtr . ToInt64 ( ) ) ;
182
+ }
183
+
184
+ /// <summary>
185
+ /// Hide windows in the Alt+Tab window list
186
+ /// </summary>
187
+ /// <param name="window">To hide a window</param>
188
+ public static void HideFromAltTab ( Window window )
189
+ {
190
+ var helper = new WindowInteropHelper ( window ) ;
191
+ var exStyle = GetWindowLong ( helper . Handle , GWL_EXSTYLE ) . ToInt32 ( ) ;
192
+
193
+ // Add TOOLWINDOW style, remove APPWINDOW style
194
+ exStyle = ( exStyle | WS_EX_TOOLWINDOW ) & ~ WS_EX_APPWINDOW ;
195
+
196
+ SetWindowLong ( helper . Handle , GWL_EXSTYLE , new IntPtr ( exStyle ) ) ;
197
+ }
198
+
199
+ /// <summary>
200
+ /// Restore window display in the Alt+Tab window list.
201
+ /// </summary>
202
+ /// <param name="window">To restore the displayed window</param>
203
+ public static void ShowInAltTab ( Window window )
204
+ {
205
+ var helper = new WindowInteropHelper ( window ) ;
206
+ var exStyle = GetWindowLong ( helper . Handle , GWL_EXSTYLE ) . ToInt32 ( ) ;
207
+
208
+ // Remove the TOOLWINDOW style and add the APPWINDOW style.
209
+ exStyle = ( exStyle & ~ WS_EX_TOOLWINDOW ) | WS_EX_APPWINDOW ;
210
+
211
+ SetWindowLong ( helper . Handle , GWL_EXSTYLE , new IntPtr ( exStyle ) ) ;
212
+ }
213
+
214
+ /// <summary>
215
+ /// To obtain the current overridden style of a window.
216
+ /// </summary>
217
+ /// <param name="window">To obtain the style dialog window</param>
218
+ /// <returns>current extension style value</returns>
219
+ public static int GetCurrentWindowStyle ( Window window )
220
+ {
221
+ var helper = new WindowInteropHelper ( window ) ;
222
+ return GetWindowLong ( helper . Handle , GWL_EXSTYLE ) . ToInt32 ( ) ;
223
+ }
224
+
225
+ #endregion
151
226
}
0 commit comments