/lib/CActiveXControl.ahk

http://github.com/Skiouros/Macro · AutoHotKey · 135 lines · 95 code · 0 blank · 40 comment · 19 complexity · 842473fa85080dadaa1e157be1db2f8a MD5 · raw file

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