-
Notifications
You must be signed in to change notification settings - Fork 72
/
Events.ahk
86 lines (71 loc) · 3.38 KB
/
Events.ahk
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
78
79
80
81
82
83
84
85
86
; This script demonstrates handling events of the Outlook Application object. Other types of objects will have different
; events.
; Usage:
; With Outlook open, run this script. Then try to send an email. The script will prevent the email from being sent and
; will display a message box.
#Persistent
; Instantiate the event handler class.
OlEvents := new OutlookApplicationEvents()
return ; End of Auto-execute section.
; Basic Outlook events class. Can be connected to an Outlook Application object.
class OutlookApplicationEvents
{
__New(olApp := "")
{
; If nothing was passed to this method, then use the active instance of Outlook. This will throw an error if
; Outlook is not running.
if (olApp = "")
olApp := ComObjActive("Outlook.Application")
; Store Outlook application object for later use (optional).
this.olApp := olApp
; Connect Outlook Application object events to this instance.
ComObjConnect(this.olApp, this)
}
; Responds to non-implemented events in a generic manner.
; Possible Outlook (2010) Application events:
; | Event Name | Implemented | Params
; | ----------------------------|---------------|-------------------------------------------------------------------
; | AdvancedSearchComplete | No | SearchObject As Search
; | AdvancedSearchStopped | No | SearchObject As Search
; | BeforeFolderSharingDialog | No | FolderToShare As Folder, Cancel As Boolean
; | ItemLoad | No | Item As Object
; | ItemSend | Yes | Item As Object, Cancel As Boolean
; | MAPILogonComplete | No | -
; | NewMail | No | -
; | NewMailEx | No | EntryIDCollection As String
; | OptionsPagesAdd | No | Pages As PropertyPages
; | Quit | Yes | -
; | Reminder | No | Item As Object
; | Startup | No | -
__Call(Event, Args*)
{
if !IsFunc( this[Event] ) { ; If this event does not correspond to a method...
ToolTip, % Event, 0, 0 ; Display the event name.
SetTimer, RemoveTT, -4000 ; Remove the tooltip in 4 seconds.
}
}
; Occurs whenever an Outlook item is sent.
ItemSend(Item, Cancel, olApp)
{
MsgBox
, 48
, Send Cancelled
, % "This email will not be sent.`n`n"
. "To: " Item.To "`n"
. "Subject: " Item.Subject
; Change the value of Cancel to true to prevent sending. -1 is True in VB.
; "[Cancel is] False [(0)] when the event occurs. If the event procedure sets this argument to True [(-1)],
; the send action is not completed and the inspector is left open."
NumPut(-1, ComObjValue(Cancel), "Short")
}
; Occurs when Outlook begins to close.
Quit(olApp)
{
ComObjConnect(olApp) ; Disconnect application events.
ExitApp ; Exit this script.
}
}
RemoveTT() {
ToolTip
}
^Esc::ExitApp ; Ctrl+Escape will exit this script.