-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskbarHelper.cs
More file actions
52 lines (45 loc) · 1.48 KB
/
Copy pathTaskbarHelper.cs
File metadata and controls
52 lines (45 loc) · 1.48 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
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace PandaDesktopApp
{
public static class TaskbarHelper
{
[DllImport("shell32.dll")]
private static extern IntPtr SHAppBarMessage(uint dwMessage, ref APPBARDATA pData);
private const int ABM_GETTASKBARPOS = 0x00000005;
[StructLayout(LayoutKind.Sequential)]
private struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public uint uCallbackMessage;
public uint uEdge;
public RECT rc;
public int lParam;
}
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int left, top, right, bottom;
}
public static Rect GetTaskbarPosition()
{
APPBARDATA abd = new APPBARDATA();
abd.cbSize = Marshal.SizeOf(typeof(APPBARDATA));
IntPtr result = SHAppBarMessage(ABM_GETTASKBARPOS, ref abd);
if (result == IntPtr.Zero)
throw new InvalidOperationException("Failed to get taskbar position.");
return new Rect(abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top);
}
public static double GetTaskbarY()
{
var rect = GetTaskbarPosition();
return rect.Top;
}
}
}