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.vb
77 lines (69 loc) · 2.32 KB
/
AlertHelper.vb
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
74
75
76
77
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraBars.Alerter
Imports System.Runtime.InteropServices
Namespace SmartAlertControl
Public NotInheritable Class AlertHelper
Private Sub New()
End Sub
Private Shared Function GetTaskbarLocation() As AlertFormLocation
Dim tbwnd As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
If tbwnd = Nothing Then
Return AlertFormLocation.BottomRight
End If
Dim abd As New AppBarData()
abd.cbSize = Marshal.SizeOf(GetType(AppBarData))
abd.hWnd = tbwnd
Dim ptr As IntPtr = Marshal.AllocHGlobal(abd.cbSize)
Try
Marshal.StructureToPtr(abd, ptr, False)
SHAppBarMessage(5, ptr)
abd = CType(Marshal.PtrToStructure(ptr, GetType(AppBarData)), AppBarData)
Finally
Marshal.FreeHGlobal(ptr)
End Try
Return GetPosition(abd.rc)
End Function
Private Shared Function GetPosition(ByVal rect As Rect) As AlertFormLocation
If rect.top = rect.left AndAlso rect.bottom > rect.right Then
Return AlertFormLocation.BottomLeft
End If
If rect.top = rect.left AndAlso rect.bottom < rect.right Then
Return AlertFormLocation.TopRight
End If
Return AlertFormLocation.BottomRight
End Function
Public Shared Sub ShowAlertNearTaskBar(ByVal alertControl As AlertControl, ByVal parent As Form, ByVal info As AlertInfo)
alertControl.FormLocation = GetTaskbarLocation()
alertControl.Show(parent, info)
End Sub
<DllImport("user32.dll")> _
Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("shell32.dll")> _
Shared Function SHAppBarMessage(ByVal dwMessage As UInteger, ByVal pAppBarData As IntPtr) As UIntPtr
End Function
<StructLayout(LayoutKind.Sequential)> _
Private Structure AppBarData
Public cbSize As Integer
Public hWnd As IntPtr
Public uCallbackMessage As UInteger
Public uEdge As UInteger
Public rc As Rect
Public lParam As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential)> _
Private Structure Rect
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
End Class
End Namespace