PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/CActiveXControl.ahk

http://github.com/Skiouros/Macro
AutoHotKey | 135 lines | 95 code | 0 blank | 40 comment | 19 complexity | 842473fa85080dadaa1e157be1db2f8a MD5 | raw file
  1/*
  2Class: CActiveXControl
  3An ActiveX control.
  4
  5This control extends <CControl>. All basic properties and functions are implemented and documented in this class.
  6
  7Variable: Accessing the properties of the ActiveX object
  8The specific properties of the ActiveX control can simply be accessed through this control object as if it were the ActiveX object itself.
  9However if you need to access the ActiveX object directly you can do so by using Control._.Object .
 10*/
 11Class CActiveXControl Extends CControl
 12{
 13	__New(Name, Options, Text, GUINum)
 14	{
 15		Base.__New(Name, Options, Text, GUINum)
 16		this.Insert("Type", "ActiveX")
 17		this._.Insert("Messages", {0x004E : "Notify"})
 18	}
 19	PostCreate()
 20	{
 21		;Acquire COM Object and connect its events with this instance
 22		GuiControlGet, object, % this.GUINum ":", % this.ClassNN
 23		this._.Object := object
 24		this._.Events := new this.CEvents(this.GUINum, this.Name, this.hwnd)
 25		ComObjConnect(object, this._.Events)
 26	}
 27	Class CEvents
 28	{
 29		__New(GUINum, ControlName, hwnd)
 30		{
 31			this.GUINum := GUINum
 32			this.ControlName := ControlName
 33			this.hwnd := hwnd
 34		}
 35		__Call(Name, Params*)
 36		{
 37			CGUI.GUIList[this.GUINum].Controls[this.hwnd].CallEvent(Name, Params*)
 38		}
 39	}
 40	/*
 41	*/
 42	__GetEx(ByRef Result, Name, Params*)
 43	{
 44		;~ global CGUI
 45		if(!Base.HasKey(Name))
 46			If Name not in Base,_,GUINum,
 47			{
 48				if(base.__GetEx(Result, Name, Params*))
 49					return true
 50				if(!CGUI.GUIList[this.GUINum].IsDestroyed)
 51				{
 52					DetectHidden := A_DetectHiddenWindows
 53					DetectHiddenWindows, On
 54					if(this.IsMemberOf(Name))
 55					{
 56						Result := this._.Object[Name]
 57						Loop % Params.MaxIndex()
 58							if(IsObject(Result)) ;Fix unlucky multi parameter __GET
 59								Result := Result[Params[A_Index]]
 60					}
 61					if(!DetectHidden)
 62						DetectHiddenWindows, Off
 63					if(Result != "")
 64						return true
 65				}
 66			}
 67	}
 68	__Set(Name, Value, Params*)
 69	{
 70		;~ global CGUI
 71		;~ If Name not in _,GUINum,Type,Options,Text,x,y,width,height,Position,Size,ClassNN,hwnd,Name,Content,Base,Focused,Tooltip
 72		if(!base.__GetEx(Result, Name, Params*))
 73			if(!CGUI.GUIList[this.GUINum].IsDestroyed)
 74			{
 75				DetectHidden := A_DetectHiddenWindows
 76				DetectHiddenWindows, On
 77				if(this.IsMemberOf(Name))
 78				{
 79					;~ Handled := true
 80					Error := ComObjError()
 81					ComObjError(false)
 82					this._.Object[Name] := Value
 83					Handled := true
 84					ComObjError(Error)
 85					if(A_LastError)
 86						Value := 0
 87				}
 88				if(!DetectHidden)
 89					DetectHiddenWindows, Off
 90				if(Handled)
 91					return Value
 92			}
 93	}
 94	__Call(Name, Params*)
 95	{
 96		if Name not in Insert,Remove,HasKey,__GetEx
 97		{
 98			if(!ObjHasKey(this.base.base, Name) && !ObjHasKey(this.base, Name) && !ObjHasKey(this.base.base.base.base, Name))
 99			{
100				Error := ComObjError()
101					ComObjError(false)
102				`(this._.Object)[Name](Params*)
103					ComObjError(Error)
104			}
105		}	
106	}
107	/*
108	Function: IsMemberOf
109	Checks if the ActiveX object supports a parameter. This does not check if it is read/write/call-able.
110	Thanks to jethrow, Lexikos and Sean for this function!
111	
112	Parameters:
113		name - the parameter to check for.
114	*/
115	IsMemberOf(name) {
116	   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
117	   ObjRelease(p)
118	   return out
119	}
120	/*
121	Event: Introduction
122	To handle control events you need to create a function with this naming scheme in your window class: ControlName_EventName(params)
123	The parameters depend on the event and there may not be params at all in some cases. 
124	You can look up the definitions of the parameters in the documentation of the ActiveX control.
125	ActiveX controls do not require a separate G-label to make the events work.
126	*/
127	;~ HandleEvent(Params*)
128	;~ {
129		;~ global CGUI
130		;~ if(CGUI.GUIList[this.GUINum].IsDestroyed)
131			;~ return
132		;~ if(IsFunc(CGUI.GUIList[this.GUINum][this.Name "_ActiveXMoved"]))
133			;~ `(CGUI.GUIList[this.GUINum])[this.Name "_ActiveXMoved"]()
134	;~ }
135}