forked from ChrisS85/CGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CActiveXControl.ahk
134 lines (130 loc) · 3.92 KB
/
CActiveXControl.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Class: CActiveXControl
An ActiveX control.
This control extends <CControl>. All basic properties and functions are implemented and documented in this class.
Property: Accessing the properties of the ActiveX object
The specific properties of the ActiveX control can simply be accessed through this control object as if it were the ActiveX object itself.
However if you need to access the ActiveX object directly you can do so by using Control._.Object .
*/
Class CActiveXControl Extends CControl
{
static registration := CGUI.RegisterControl("ActiveX", CActiveXControl)
__New(Name, Options, Text, GUINum)
{
Base.__New(Name, Options, Text, GUINum)
this.Insert("Type", "ActiveX")
; this._.Insert("Messages", {0x004E : "Notify"})
}
PostCreate()
{
;Acquire COM Object and connect its events with this instance
GuiControlGet, object, % this.GUINum ":", % this.ClassNN
this._.Object := object
this._.Events := new this.CEvents(this.GUINum, this.Name, this.hwnd)
ComObjConnect(object, this._.Events)
}
Class CEvents
{
__New(GUINum, ControlName, hwnd)
{
this.GUINum := GUINum
this.ControlName := ControlName
this.hwnd := hwnd
}
__Call(Name, Params*)
{
CGUI.GUIList[this.GUINum].Controls[this.hwnd].CallEvent(Name, Params*)
}
}
/*
*/
__GetEx(ByRef Result, Name, Params*)
{
if(!Base.HasKey(Name))
If Name not in Base,_,GUINum,
{
if(base.__GetEx(Result, Name, Params*))
return true
if(!CGUI.GUIList[this.GUINum].IsDestroyed)
{
DetectHidden := A_DetectHiddenWindows
DetectHiddenWindows, On
if(this.IsMemberOf(Name))
{
Result := this._.Object[Name]
Loop % Params.MaxIndex()
if(IsObject(Result)) ;Fix unlucky multi parameter __GET
Result := Result[Params[A_Index]]
}
if(!DetectHidden)
DetectHiddenWindows, Off
if(Result != "")
return true
}
}
}
__Set(Name, Value, Params*)
{
;~ If Name not in _,GUINum,Type,Options,Text,x,y,width,height,Position,Size,ClassNN,hwnd,Name,Content,Base,Focused,Tooltip
if(!base.__GetEx(Result, Name, Params*))
if(!CGUI.GUIList[this.GUINum].IsDestroyed)
{
DetectHidden := A_DetectHiddenWindows
DetectHiddenWindows, On
if(this.IsMemberOf(Name))
{
;~ Handled := true
Error := ComObjError()
ComObjError(false)
this._.Object[Name] := Value
Handled := true
ComObjError(Error)
if(A_LastError)
Value := 0
}
if(!DetectHidden)
DetectHiddenWindows, Off
if(Handled)
return Value
}
}
__Call(Name, Params*)
{
if Name not in Insert,Remove,HasKey,__GetEx
{
if(!ObjHasKey(this.base.base, Name) && !ObjHasKey(this.base, Name) && !ObjHasKey(this.base.base.base.base, Name))
{
Error := ComObjError()
ComObjError(false)
(this._.Object)[Name](Params*)
ComObjError(Error)
}
}
}
/*
Function: IsMemberOf
Checks if the ActiveX object supports a parameter. This does not check if it is read/write/call-able.
Thanks to jethrow, Lexikos and Sean for this function!
Parameters:
name - the parameter to check for.
*/
IsMemberOf(name) {
out := DllCall(NumGet(NumGet(1*p:=ComObjUnwrap(this._.Object))+A_PtrSize*5), "Ptr",p, "Ptr",VarSetCapacity(iid,16,0)*0+&iid, "Ptr*",&name, "UInt",1, "UInt",1024, "Int*",dispID)=0 && dispID+1
ObjRelease(p)
return out
}
/*
Event: Introduction
To handle control events you need to create a function with this naming scheme in your window class: ControlName_EventName(params)
The parameters depend on the event and there may not be params at all in some cases.
You can look up the definitions of the parameters in the documentation of the ActiveX control.
ActiveX controls do not require a separate G-label to make the events work.
*/
;~ HandleEvent(Params*)
;~ {
;~ if(CGUI.GUIList[this.GUINum].IsDestroyed)
;~ return
;~ if(IsFunc(CGUI.GUIList[this.GUINum][this.Name "_ActiveXMoved"]))
;~ (CGUI.GUIList[this.GUINum])[this.Name "_ActiveXMoved"]()
;~ }
}