ActiveX (COM) Ereignisse (Events)

Hilfreiche Erklärungen und Tipps zum Lernen von Autohotkey

Moderator: jNizM

just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

ActiveX (COM) Ereignisse (Events)

23 Jan 2014, 04:52

Ich habe nach wie vor ziemliche Probleme mit ActiveX-Controls (bzw. COM-Objekten). Obwohl ich mich im MSDN inzwischen relativ heimisch fühle, gelingt es mir sehr oft nicht, für diese Komponenten die entscheidenden Informationen zu finden. Für den ActiveX-Teil habe ich mir deshalb eine Helferklasse erstellt, die mir zeigt, was mir die Controls so alles sagen wollen (falls es so etwas bereits im alten Forum gibt, habe ich das auch nicht gefunden :roll: ). Weil mir das recht brauchbar erscheint und es auch Anderen helfen könnte, sich in diesem Dschungel zu orientieren, poste ich das hier als 'Tutorial'. Wenn Einer, der mit diesem Stoff besser umgehen kann, eine ähnliche Lösung für das Ermitteln der Eigenschaften / Properties hat, wäre das als Ergänzung ideal.

Code: Select all

#NoEnv
SetBatchLines, -1
; Ausgabe in die Datei EventMon.txt
LogFilePath := A_ScriptDir . "\EventMon.txt"
LogFileObject := FileOpen(LogFilePath, "w")
EventMonitor.FileObject := LogFileObject
; Aus der AHK Hilfe
Gui Add, Edit, w930 r1 vURL, http://ahkscript.org/boards/
Gui Add, Button, x+6 yp w44 Default, Go
Gui Add, ActiveX, xm w980 h640 vWB, Shell.Explorer 
ComObjConnect(WB, EventMonitor)  ; Connect events to the EventMonitor class object.
Gui, Show, , Event Monitor
; Continue on to load the initial page:
ButtonGo:
Gui Submit, NoHide
WB.Navigate(URL)
Return
; ----------------------------------------------------------------------------------------------------------------------
GuiClose:
   If IsObject(LogFileObject) {
      LogFileObject.CLose()
      Run, Notepad.exe "%LogFilePath%", %A_ScriptDir%
   }
ExitApp
; ======================================================================================================================
; ActiveX / COM Event Monitor
; ======================================================================================================================
Class EventMonitor Extends EventMonitor_Base {
   ; If you set FileObject to the handle to an open file, all output will be written into this file.
   ; Otherwise, output will be send to the debugger (if any) per OutputDebug.
   ; Wenn in FileObject das 'Handle' einer zum Schreiben geöffneten Datei abgelegt wird, werden die Ausgaben in diese
   ; Datei geschrieben.
   ; Anderenfalls werden die Ausgaben per OutputDebug an den Debugger gesendet, falls einer läuft.
   Static FileObject := 0
}
Class EventMonitor_Base {
   __Call(Func, Params*) {
      ; http://www.ahkscript.org/docs/commands/ComObjType.htm
      Static VT_BYREF := 16384
      Static ComTypes := {0: "VT_EMPTY", 1: "VT_NULL", 2: "VT_I2", 3: "VT_I4", 4: "VT_R4", 5: "VT_R8", 6: "VT_CY"
                        , 7: "VT_DATE", 8: "VT_BSTR", 9: "VT_DISPATCH", 10: "VT_ERROR", 11: "VT_BOOL"
                        , 12: "VT_VARIANT", 13: "VT_UNKNOWN", 14: "VT_DECIMAL", 16: "VT_I1", 17: "VT_UI1"
                        , 18: "VT_UI2", 19: "VT_UI4", 20: "VT_I8", 21: "VT_UI8", 22: "VT_INT", 23: "VT_UINT"
                        , 36: "VT_RECORD", 8192: "VT_ARRAY", 16384: "VT_BYREF"}
      Msg := "Event: " . Func . " >>> Params = " . Params.MaxIndex() . " :"
      For Index, Param In Params {
         ParamOut := Param
         If IsObject(Param) {
            OutType := ""
            ComType := ComObjType(Param)
            If (ComType > VT_BYREF) {
               ComType -= VT_BYREF
               OutType := ComTypes[VT_BYREF] . "->"
            }
            OutType .= ComTypes.HasKey(ComType) ? ComTypes[ComType] : ComTYpe
            OutName := ComObjType(Param, "Name")
            ParamOut := OutName ? "OBJNAME: " . OutName : "OBJTYPE: " . OutType
         }
         Msg .= (Index = 1 ?  " " : " - ") . ParamOut
      }
      If (IsObject(This.FileObject))
         This.FileObject.Write(Msg . "`r`n")
      Else
         OutputDebug, %Msg%
   }
}

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 18 guests