This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlertHelper.cs
73 lines (65 loc) · 2.31 KB
/
AlertHelper.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars.Alerter;
using System.Runtime.InteropServices;
namespace SmartAlertControl
{
public static class AlertHelper
{
private static AlertFormLocation GetTaskbarLocation()
{
IntPtr tbwnd = FindWindow("Shell_TrayWnd", null);
if (tbwnd == null) return AlertFormLocation.BottomRight;
AppBarData abd = new AppBarData();
abd.cbSize = Marshal.SizeOf(typeof(AppBarData));
abd.hWnd = tbwnd;
IntPtr ptr = Marshal.AllocHGlobal(abd.cbSize);
try
{
Marshal.StructureToPtr(abd, ptr, false);
SHAppBarMessage(5, ptr);
abd = (AppBarData)Marshal.PtrToStructure(ptr, typeof(AppBarData));
}
finally { Marshal.FreeHGlobal(ptr); }
return GetPosition(abd.rc);
}
private static AlertFormLocation GetPosition(Rect rect)
{
if (rect.top == rect.left && rect.bottom > rect.right) return AlertFormLocation.BottomLeft;
if (rect.top == rect.left && rect.bottom < rect.right) return AlertFormLocation.TopRight;
return AlertFormLocation.BottomRight;
}
public static void ShowAlertNearTaskBar(AlertControl alertControl, Form parent, AlertInfo info)
{
alertControl.FormLocation = GetTaskbarLocation();
alertControl.Show(parent, info);
}
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("shell32.dll")]
static extern UIntPtr SHAppBarMessage(uint dwMessage, IntPtr pAppBarData);
[StructLayout(LayoutKind.Sequential)]
private struct AppBarData
{
public int cbSize;
public IntPtr hWnd;
public uint uCallbackMessage;
public uint uEdge;
public Rect rc;
public IntPtr lParam;
}
[StructLayout(LayoutKind.Sequential)]
private struct Rect
{
public int left;
public int top;
public int right;
public int bottom;
}
}
}