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