-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedrawTaskbar.csx
More file actions
47 lines (32 loc) · 1.44 KB
/
RedrawTaskbar.csx
File metadata and controls
47 lines (32 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env dotnet-script
// https://github.com/vurdalakov/scripttools/
using System.Runtime.InteropServices;
var taskbarHandle = FindWindow("Shell_TrayWnd", null);
if (IntPtr.Zero == taskbarHandle)
{
Console.WriteLine("Cannot find taskbar window");
return;
}
// approach 1
SendMessageTimeout(taskbarHandle, WM_SETTINGCHANGE, UIntPtr.Zero, IntPtr.Zero, SMTO_ABORTIFHUNG, 1000, out _);
// approach 2
ShowWindow(taskbarHandle, SW_HIDE);
ShowWindow(taskbarHandle, SW_SHOW);
// approach 3
InvalidateRect(taskbarHandle, IntPtr.Zero, true);
UpdateWindow(taskbarHandle);
private const UInt32 HWND_BROADCAST = 0xFFFF;
private const UInt32 WM_SETTINGCHANGE = 0x001A;
private const UInt32 SMTO_ABORTIFHUNG = 0x0002;
private const Int32 SW_HIDE = 0;
private const Int32 SW_SHOW = 5;
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr SendMessageTimeout(IntPtr hWnd, UInt32 Msg, UIntPtr wParam, IntPtr lParam, UInt32 fuFlags, UInt32 uTimeout, out IntPtr lpdwResult);
[DllImport("user32.dll")]
private static extern Boolean InvalidateRect(IntPtr hWnd, IntPtr lpRect, Boolean bErase);
[DllImport("user32.dll")]
private static extern Boolean UpdateWindow(IntPtr hWnd);