Jump to content

HtmLayout DLL UDF !


GMib
 Share

Recommended Posts

I finally managed to run HtmLayout.dll,

HtmLayout is a fast, lightweight and embeddable HTML/CSS renderer and layout manager component.

Download dll here : http://www.terrainformatica.com/htmlayout/HTMLayoutDLL.zip

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <HtmLayout Constants.au3>
#include-once

Global $aHLelementsfound = 0
Global $HtmLayoutdll = 0
Global $HtmLayoutRef = 0
Global $HandleWindowsAttachEvent = 0
Global $HtmLayoutEvHandler = 0
Global $aHLDOM_error[7]
$aHLDOM_error[0] = "function completed successfully"
$aHLDOM_error[1] = "invalid HWND"
$aHLDOM_error[2] = "invalid HELEMENT"
$aHLDOM_error[3] = "attempt to use HELEMENT which is not marked by HTMLayout_UseElement()"
$aHLDOM_error[4] = "parameter is invalid, e.g. pointer is null"
$aHLDOM_error[5] = "operation failed, e.g. invalid html in HTMLayoutSetElementHtml()"
$aHLDOM_error[6] = "Dllcall error"

; #FUNCTION# ====================================================================================================
; Name...........:  _HLStartup
; Description....:  Initialize HtmLayout
; Syntax.........:  _HLStartup($dll = "HtmLayout.dll")
; Parameters.....:  $dll - Path to HtmLayout DLL [Optional]
;
; Return values..:  Success - 1
;                   Failure - 0
; Remarks........:
; ===============================================================================================================
Func _HLStartup($dll = "HtmLayout.dll")
    $HtmLayoutRef += 1
    If $HtmLayoutRef > 1 Then Return 1
    $HtmLayoutdll = DllOpen($dll)
    If $HtmLayoutdll = -1 Then Return SetError(1, 0, 0)
    Return 1
EndFunc

; #FUNCTION# ====================================================================================================
; Name...........:  _HLCreateGui
; Description....:  Create HtmLayout Windows
; Syntax.........:  _HLCreateGui($ParentGui, $x = 0, $y = 0, $w = 100, $h = 50)
; Parameters.....:  $ParentGui - Handle of parent Gui
;                   $x - [Optional]
;                   $y - [Optional]
;                   $w - [Optional]
;                   $h - [Optional]
;
; Return values..:  Success - HTMLayout window handle.
;                   Failure - 0
; Remarks........:
; ===============================================================================================================
Func _HLCreateGui($ParentGui, $x = 0, $y = 0, $w = 100, $h = 50)
    $result = DllCall($HtmLayoutdll, "wstr", "HTMLayoutClassNameW")
    If @error Then Return 0
    $ClassName = $result[0]
    $HtmLayoutHwnd = _WinAPI_CreateWindowEx(0, $ClassName, "", BitOR($WS_CHILD, $WS_VISIBLE, $WS_CLIPCHILDREN), $x, $y, $w, $h, $ParentGui)
    Return $HtmLayoutHwnd
EndFunc   ;==>_HLCreateGui

; #FUNCTION# ====================================================================================================
; Name...........:  _HLLoadFile
; Description....:  Load HTML file.
; Syntax.........:  _HLLoadFile($HLHwnd, $file)
; Parameters.....:  $HLHwnd - HTMLayout window handle.
;                   $file - File name of an HTML file.
;
; Return values..:  Success - 1
;                   Failure - 0
; Remarks........:
; ===============================================================================================================
Func _HLLoadFile($HLHwnd, $file)
    $result = DllCall($HtmLayoutdll, "BOOL", "HTMLayoutLoadFile", "HWND", $HLHwnd, "wstr", $file)
    Return $result[0]
EndFunc   ;==>_HLLoadFile

; #FUNCTION# ====================================================================================================
; Name...........:  _HLLoadHtml
; Description....:  Load HTML from memory.
; Syntax.........:  _HLLoadHtml($HLHwnd, $String)
; Parameters.....:  $HLHwnd - HTMLayout window handle.
;                   $String - HTML to load.
;
; Return values..:  Success - 1
;                   Failure - 0
; Remarks........:
; ===============================================================================================================
Func _HLLoadHtml($HLHwnd, $String)
    $StringSize = StringLen($String)
    $result = DllCall($HtmLayoutdll, "BOOL", "HTMLayoutLoadHtml", "HWND", $HLHwnd, "str", $String, "UINT", $StringSize)
    Return $result[0]
EndFunc   ;==>_HLLoadHtml

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetRootElement
; Description....:  Get root DOM element of HTML document.
; Syntax.........:  _HLGetRootElement($HLHwnd)
; Parameters.....:  $HLHwnd - HTMLayout window handle.
;
; Return values..:  Success - Return root element.
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........: Root DOM object is always a 'HTML' element of the document.
; ===============================================================================================================
Func _HLGetRootElement($HLHwnd)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetRootElement", "HWND", $HLHwnd, "ptr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetRootElement

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetChildrenCount
; Description....:  Get number of child elements.
; Syntax.........:  _HLGetChildrenCount($el)
; Parameters.....:  $el - DOM element handle which child elements you need to count
;
; Return values..:  Success - Return number of child elements
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetChildrenCount($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetChildrenCount", "ptr", $el, "UINT*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetChildrenCount

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetNthChild
; Description....:  Get handle of Nth child element.
; Syntax.........:  _HLGetNthChild($el, $nth)
; Parameters.....:  $el - DOM element handle
;                   $nth - number of the child element
;
; Return values..:  Success - Return handle of the child element
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetNthChild($el, $nth)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetNthChild", "ptr", $el, "UINT", $nth-1, "ptr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[3]
EndFunc   ;==>_HLGetNthChild

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetParentElement
; Description....:  Get parent element.
; Syntax.........:  _HLGetParentElement($el)
; Parameters.....:  $el - DOM element handle which parent you need
;
; Return values..:  Success - Return handle of the parent element
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetParentElement($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetParentElement", "ptr", $el, "ptr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetParentElement

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetElementHtml
; Description....:  Get Html of the element.
; Syntax.........:  _HLGetElementHtml($el, $outer = 1)
; Parameters.....:  $el - DOM element handle
;                   $outer - BOOL, if TRUE will return outer HTML otherwise inner. [Optional]
;
; Return values..:  Success - Return Html of element
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetElementHtml($el, $outer = 1)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetElementHtml", "ptr", $el, "str*", "", "BOOL", $outer)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetElementHtml

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetElementInnerText
; Description....:  Get inner text of the element.
; Syntax.........:  _HLGetElementInnerText($el)
; Parameters.....:  $el - DOM element handle
;
; Return values..:  Success - Return innertext of element
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetElementInnerText($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetElementInnerText", "ptr", $el, "str*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetElementInnerText

; #FUNCTION# ====================================================================================================
; Name...........:  _HLSetElementInnerText
; Description....:  Set inner text of the element.
; Syntax.........:  _HLSetElementInnerText($el, $String)
; Parameters.....:  $el - DOM element handle
;                   $String - Innertext
;
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLSetElementInnerText($el, $String)
    $len = StringLen($String)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutSetElementInnerText", "ptr", $el, "str", $String, "UINT", $len)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return 1
EndFunc   ;==>_HLSetElementInnerText

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetAttributeCount
; Description....:  Get number of element's attributes.
; Syntax.........:  _HLGetAttributeCount($el)
; Parameters.....:  $el - DOM element handle
;
; Return values..:  Success - Return number of element attributes.
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetAttributeCount($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetAttributeCount", "ptr", $el, "UINT*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetAttributeCount

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetNthAttribute
; Description....:  Get value of any element's attribute by attribute's number.
; Syntax.........:  _HLGetNthAttribute($el, $nth)
; Parameters.....:  $el - DOM element handle
;                   $nth - number of desired attribute
;
; Return values..:  Success - Return Array with name and value of attribute. $return[0] = name, $return[1] = value
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetNthAttribute($el, $nth)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetNthAttribute", "ptr", $el, "UINT", $nth, "str*", "", "wstr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Dim $aRet[2]
    $aRet[0] = $result[3]
    $aRet[1] = $result[4]
    Return $aRet
EndFunc   ;==>_HLGetNthAttribute

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetAttributeByName
; Description....:  Get value of any element's attribute by name.
; Syntax.........:  _HLGetAttributeByName($el, $AttName)
; Parameters.....:  $el - DOM element handle
;                   $AttName - attribute name
;
; Return values..:  Success - Return attribute value
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetAttributeByName($el, $AttName)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetAttributeByName", "ptr", $el, "str", $AttName, "wstr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[3]
EndFunc   ;==>_HLGetAttributeByName

; #FUNCTION# ====================================================================================================
; Name...........:  _HLSetAttributeByName
; Description....:  Set attribute's value.
; Syntax.........:  _HLSetAttributeByName($el, $AttName, $value)
; Parameters.....:  $el - DOM element handle
;                   $AttName - attribute name
;                   $value - new attribute value or 0 if you want to remove attribute.
;
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLSetAttributeByName($el, $AttName, $value)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutSetAttributeByName", "ptr", $el, "str", $AttName, "wstr", $value)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return 1
EndFunc   ;==>_HLSetAttributeByName

; #FUNCTION# ====================================================================================================
; Name...........:  _HLClearAttributes
; Description....:  Remove all attributes from the element.
; Syntax.........:  _HLClearAttributes($el)
; Parameters.....:  $el - DOM element handle
;
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLClearAttributes($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutClearAttributes", "ptr", $el)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return 1
EndFunc   ;==>_HLClearAttributes

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetElementIndex
; Description....:  Get element index.
; Syntax.........:  _HLGetElementIndex($el)
; Parameters.....:  $el - DOM element handle
;
; Return values..:  Success - Return index of element
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetElementIndex($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetElementIndex", "ptr", $el, "UINT*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetElementIndex

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetElementType
; Description....:  Get element's type.
; Syntax.........:  _HLGetElementType($el)
; Parameters.....:  $el - DOM element handle
;
; Return values..:  Success - Return Type of element
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetElementType($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetElementType", "ptr", $el, "str*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[2]
EndFunc   ;==>_HLGetElementType

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetStyleAttribute
; Description....:  Get element's style attribute.
; Syntax.........:  _HLGetStyleAttribute($el, $StyleName)
; Parameters.....:  $el - DOM element handle
;                   $StyleName - name of the style attribute
;
; Return values..:  Success - Return value of the style attribute.
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLGetStyleAttribute($el, $StyleName)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutGetStyleAttribute", "ptr", $el, "wstr", $StyleName, "wstr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[3]
EndFunc   ;==>_HLGetStyleAttribute

; #FUNCTION# ====================================================================================================
; Name...........:  _HLSetStyleAttribute
; Description....:  Set element's style attribute.
; Syntax.........:  _HLSetStyleAttribute($el, $StyleName, $StyleValue)
; Parameters.....:  $el - DOM element handle
;                   $StyleName - name of the style attribute
;                   $StyleValue - value of the style attribute.
;
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLSetStyleAttribute($el, $StyleName, $StyleValue)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutSetStyleAttribute", "ptr", $el, "str", $StyleName, "wstr", $StyleValue)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return 1
EndFunc   ;==>_HLSetStyleAttribute

; #FUNCTION# ====================================================================================================
; Name...........:  _HLVisitElements
; Description....:  Return Array of elements in a DOM that meets specified criteria.
; Syntax.........:  _HLVisitElements($el, $TagName = "", $AttributeName = "", $AttributeValue = "", $depth = 0)
; Parameters.....:  $el - DOM element handle
;                   $TagName - comma separated list of tag names to search, e.g. "div", "p", "div,p" etc. [Optional]
;                   $AttributeName - name of attribute, can contain wildcard characters. [Optional]
;                   $AttributeValue - value of attribute, can contain wildcard characters.[Optional]
;                   $depth - 0 means all descendants, 1 - direct children only, 2 - children and their children and so on. [Optional]
;
; Return values..:  Success - Return array of element, $return[0] : number of element.
;                   Failure - Return 0 if no element found else Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLVisitElements($el, $TagName = "", $AttributeName = "", $AttributeValue = "", $depth = 0)
    $TagType = "str"
    $AttType = "str"
    $AttVType = "wstr"
    If $TagName = "" Then $TagType = "ptr"
    If $AttributeName = "" Then $AttType = "ptr"
    If $AttributeValue = "" Then $AttVType = "ptr"
    $handle = DllCallbackRegister("_HLElementsCallback", "BOOL", "ptr;ptr")
    Dim $aHLelementsfound[1]
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutVisitElements", "ptr", $el, $TagType, $TagName, $AttType, $AttributeName, $AttVType, $AttributeValue, "ptr", DllCallbackGetPtr($handle), "ptr", "", "DWORD", $depth)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    DllCallbackFree($handle)
    $HLelementsCount = UBound($aHLelementsfound)
    If $HLelementsCount = 1 Then Return 0
    $aHLelementsfound[0] = $HLelementsCount-1
    Return $aHLelementsfound
EndFunc   ;==>_HLVisitElements

Func _HLElementsCallback($el, $param)
    Local $iUBound = UBound($aHLelementsfound)
    ReDim $aHLelementsfound[$iUBound + 1]
    $aHLelementsfound[$iUBound] = $el
EndFunc   ;==>_HLElementsCallback

; #FUNCTION# ====================================================================================================
; Name...........:  _HLSelectElements
; Description....:  Return Array of elements in a DOM that meets specified CSS selectors.
; Syntax.........:  _HLSelectElements($el, $CssSel)
; Parameters.....:  $el - DOM element handle
;                   $CssSel - comma separated list of CSS selectors, e.g.: div, id, div[align="right"].
;
; Return values..:  Success - Return Array of elements, $return[0] : number of element.
;                   Failure - Return 0 if no element found else Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:  See list of supported selectors: http://terrainformatica.com/htmlayout/selectors.whtm
; ===============================================================================================================
Func _HLSelectElements($el, $CssSel)
    $handle = DllCallbackRegister("_HLElementsCallback", "BOOL", "ptr;ptr")
    Dim $aHLelementsfound[1]
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutSelectElements", "ptr", $el, "str", $CssSel, "ptr", DllCallbackGetPtr($handle), "ptr", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    DllCallbackFree($handle)
    $HLelementsCount = UBound($aHLelementsfound)
    If $HLelementsCount = 1 Then Return 0
    $aHLelementsfound[0] = $HLelementsCount-1
    Return $aHLelementsfound
EndFunc   ;==>_HLSelectElements

; #FUNCTION# ====================================================================================================
; Name...........:  _HLSelectParent
; Description....:  Find parent of the element by CSS selector.
; Syntax.........:  _HLSelectParent($el, $CssSel, $depth = 0)
; Parameters.....:  $el - DOM element handle
;                   $CssSel - comma separated list of CSS selectors, e.g.: div, id, div[align="right"].
;                   $depth - if depth == 1 then it will test only element itself.
;                            Use depth = 1 if you just want to test he element for matching given CSS selector(s).
;                            depth = 0 will scan the whole child parent chain up to the root. [Optional]
;
; Return values..:  Success - Return parent of the element.
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:
; ===============================================================================================================
Func _HLSelectParent($el, $CssSel, $depth = 0)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutSelectParent", "ptr", $el, "str", $CssSel, "UINT", $depth, "ptr*", "")
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return $result[4]
EndFunc   ;==>_HLSelectParent

; #FUNCTION# ====================================================================================================
; Name...........:  _HLSetElementHtml
; Description....:  Set inner or outer html of the element.
; Syntax.........:  _HLSetElementHtml($el, $html, $where)
; Parameters.....:  $el - DOM element handle
;                   $html - string containing html text
;                   $where - possible values are:
;                           0: replace content of the element
;                           1: insert html before first child of the element
;                           2: insert html after last child of the element
;                           3: replace element by html, a.k.a. element.outerHtml = "something"
;                           4: insert html before the element
;                           5: insert html after the element
;
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:  Value 3,4 and 5 for $where do not work for inline elements like
; ===============================================================================================================
Func _HLSetElementHtml($el, $html, $where)
    $htmllen = StringLen($html)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutSetElementHtml", "ptr", $el, "str", $html, "DWORD", $htmllen, "UINT", $where)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return 1
EndFunc   ;==>_HLSetElementHtml

; #FUNCTION# ====================================================================================================
; Name...........:  _HLDeleteElement
; Description....:  Delete element.
; Syntax.........:  _HLDeleteElement($el)
; Parameters.....:  $el - DOM element handle
;
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:  After call to this function $el will become invalid.
; ===============================================================================================================
Func _HLDeleteElement($el)
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutDeleteElement", "ptr", $el)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    Return 1
EndFunc   ;==>_HLDeleteElement


;~ EXTERN_C HLDOM_RESULT HLAPI  HTMLayoutShowPopup (HELEMENT hePopup, HELEMENT heAnchor, UINT placement)
;~   Shows block element (DIV) in popup window.
;~ Func _HLShowPopup($HtmLayoutdll, $el, $anchor, $placement)
;~  $result = DllCall($HtmLayoutdll, "int", "HTMLayoutShowPopup", "ptr", $el, "ptr", $anchor, "UINT", $placement)
;~  If @error Then Return 0
;~  Return 1
;~ EndFunc

; #FUNCTION# ====================================================================================================
; Name...........:  _HLWindowAttachEventHandler
; Description....:  Attach/Detach ElementEventProc to the htmlayout window.
; Syntax.........:  _HLWindowAttachEventHandler($hwnd, $func)
; Parameters.....:  $hwnd - HWND of HtmLayout windows
;                   $func - Function to receive events (need two params eg: $func($ev, $prm)
;                   $events - Events you want receive (see remarks)
; Return values..:  Success - Return 1
;                   Failure - Return -1, @error is set. (see $aHLDOM_error[@error] for details)
; Remarks........:  _HLGetParam must use for read param of event.
;~                  Events can be :
;~                  $HANDLE_INITIALIZATION  : attached/detached
;~                  $HANDLE_MOUSE           : mouse events
;~                  $HANDLE_KEY             : key events
;~                  $HANDLE_FOCUS           : focus events, if this flag is set it also means that element it attached to is focusable
;~                  $HANDLE_SCROLL          : scroll events
;~                  $HANDLE_SIZE            : size changed event
;~                  $HANDLE_DATA_ARRIVED    : requested data () has been delivered
;~                  $HANDLE_BEHAVIOR_EVENT  : secondary, synthetic events:
;~                                              BUTTON_CLICK, HYPERLINK_CLICK, etc.,
;~                                              a.k.a. notifications from intrinsic behaviors
;~                  $HANDLE_METHOD_CALL     : behavior specific methods
;~                  $HANDLE_EXCHANGE        : system drag-n-drop events
;~                  $HANDLE_ALL             : all of them
; ===============================================================================================================
Func _HLWindowAttachEventHandler($hwnd, $func, $events)

    $HandleWindowsAttachEvent = DllCallbackRegister("HLEvHandler", "BOOL", "ptr;ptr;UINT;ptr")
    $result = DllCall($HtmLayoutdll, "int", "HTMLayoutWindowAttachEventHandler", "HWND", $hwnd, "ptr", DllCallbackGetPtr($HandleWindowsAttachEvent), "ptr", "", "UINT", $DISABLE_INITIALIZATION+$events)
    If @error Then Return SetError(6,0,-1)
    If $result[0] <> 0 Then SetError($result[0],0,-1)
    $HtmLayoutEvHandler = $func
    Return 1
EndFunc   ;==>_HLWindowAttachEventHandler

Func HLEvHandler($tag,$el,$ev,$prm)

    $a = DllStructCreate("UINT cmd", $prm)
    $cmd = DllStructGetData($a, "cmd")
    $a = 0
    If $cmd > 32768 Then Return


    Execute ($HtmLayoutEvHandler&"("&$ev&","&$prm&")")

EndFunc

; #FUNCTION# ====================================================================================================
; Name...........:  _HLGetParam
; Description....:  Get parameter of events
; Syntax.........:  _HLGetParam($ev, $prm)
; Parameters.....:  $ev - Type of event see remarks of _HLWindowAttachEventHandler
;                   $prm - Parameter of event
;
; Return values..:  Success - return an array depending of event
;                   Failure - Return -1
; Remarks........:  For Uppercase type see "HtmLayout Constants.au3"
;       $HANDLE_MOUSE : $ret[12]=[MOUSE_EVENTS, target el, curs xpos el rel, curs ypos el rel, curs xpos doc rel, curs ypos doc rel, MOUSE_BUTTONS, KEYBOARD_STATES, CURSOR_TYPE, is on icon, el dragged, DRAGGING_TYPE]
;       $HANDLE_KEY   : $ret[4]=[KEY_EVENTS, target el, key code, KEYBOARD_STATES]
;       $HANDLE_FOCUS : $ret[4]=[FOCUS_EVENTS, target el, focus by click, cancel]
;       $HANDLE_SCROLL: $ret[4]=[SCROLL_EVENTS, target el, scroll pos, 1 if vert scroll]
;       $HANDLE_BEHAVIOR_EVENT : $ret[5]=[BEHAVIOR_EVENTS, target el, source el, EVENT_REASON or EDIT_CHANGED_REASON, data]
;===============================================================================================================
Func _HLGetParam($ev, $prm)
    Local $ap = -1

    If $ev = $HANDLE_MOUSE Then
        $str = "UINT cmd;ptr target;DWORD posx;DWORD posy;DWORD pos_documentx;DWORD pos_documenty;UINT button_state;UINT alt_state;UINT cursor_type;BOOL is_on_icon;ptr dragging;UINT dragging_mode"
        $ap = getstructdata($str,$prm)
    EndIf
    If $ev = $HANDLE_KEY Then
        $str = "UINT cmd;ptr target;UINT key_code;UINT alt_state"
        $ap = getstructdata($str,$prm)
    EndIf
    If $ev = $HANDLE_FOCUS Then
        $str = "UINT cmd;ptr target;BOOL by_mouse_click;BOOL cancel"
        $ap = getstructdata($str,$prm)
    EndIf
    If $ev = $HANDLE_SCROLL Then
        $str = "UINT cmd;ptr target;int pos;BOOL vertical"
        $ap = getstructdata($str,$prm)
    EndIf
    If $ev = $HANDLE_BEHAVIOR_EVENT Then
        $str = "UINT cmd;ptr heTarget;ptr he;UINT reason;ptr data"
        $ap = getstructdata($str,$prm)
    EndIf
    If $ev = $HANDLE_METHOD_CALL Then
        $str = "UINT cmd;ptr heTarget;ptr he;UINT reason;ptr data"
        $ap = getstructdata($str,$prm)
    EndIf

    Return $ap
EndFunc

Func getstructdata($str,$prm)
    $a = DllStructCreate($str, $prm)
    $b = StringSplit ( $str, ";")
    Dim $ret[$b[0]]
    For $i = 0 To $b[0]-1
        $ret[$i] = DllStructGetData($a,$i+1)
    Next
    Return $ret
EndFunc

post-55441-12720431967425_thumb.jpg

Edit: add some function.

User calltips :

_HLStartup ($dll = "HtmLayout.dll")  Initialize HtmLayout (required: #include <HtmLayout UDF.au3>)
_HLCreateGui ($ParentGui, $x = 0, $y = 0, $w = 100, $h = 50)  Create HtmLayout Windows (required: #include <HtmLayout UDF.au3>)
_HLLoadFile ($HLHwnd, $file)  Load HTML file. (required: #include <HtmLayout UDF.au3>)
_HLLoadHtml ($HLHwnd, $String)  Load HTML from memory. (required: #include <HtmLayout UDF.au3>)
_HLGetRootElement ($HLHwnd)  Get root DOM element of HTML document. (required: #include <HtmLayout UDF.au3>)
_HLGetChildrenCount ($el)  Get number of child elements. (required: #include <HtmLayout UDF.au3>)
_HLGetGetFocusElement ($hwnd)  Get focused DOM element of HTML document. (required: #include <HtmLayout UDF.au3>)
_HLGetGetElementState ($el)  Get state bits, see ELEMENT_STATE_BITS in "HtmLayout constats.au3" (required: #include <HtmLayout UDF.au3>)
_HLSetElementState ($el, $stateToSet, $stateToClear = 0, $upt = 1)  Set state bits, see ELEMENT_STATE_BITS in "HtmLayout constats.au3" (required: #include <HtmLayout UDF.au3>)
_HLGetNthChild ($el, $nth)  Get handle of Nth child element. (required: #include <HtmLayout UDF.au3>)
_HLGetParentElement ($el)  Get parent element. (required: #include <HtmLayout UDF.au3>)
_HLGetElementHtml ($el, $outer = 1)  Get Html of the element. (required: #include <HtmLayout UDF.au3>)
_HLGetElementInnerText ($el)  Get inner text of the element. (required: #include <HtmLayout UDF.au3>)
_HLSetElementInnerText ($el, $String)  Set inner text of the element. (required: #include <HtmLayout UDF.au3>)
_HLGetAttributeCount ($el)  Get number of element's attributes. (required: #include <HtmLayout UDF.au3>)
_HLGetNthAttribute ($el, $nth)  Get value of any element's attribute by attribute's number. (required: #include <HtmLayout UDF.au3>)
_HLGetAttributeByName ($el, $AttName)  Get value of any element's attribute by name. (required: #include <HtmLayout UDF.au3>)
_HLSetAttributeByName ($el, $AttName, $value)  Set attribute's value. (required: #include <HtmLayout UDF.au3>)
_HLClearAttributes ($el)  Remove all attributes from the element. (required: #include <HtmLayout UDF.au3>)
_HLGetElementIndex ($el)  Get element index. (required: #include <HtmLayout UDF.au3>)
_HLGetElementType ($el)  Get element's type. (required: #include <HtmLayout UDF.au3>)
_HLGetStyleAttribute ($el, $StyleName)  Get element's style attribute. (required: #include <HtmLayout UDF.au3>)
_HLSetStyleAttribute ($el, $StyleName, $StyleValue)  Set element's style attribute. (required: #include <HtmLayout UDF.au3>)
_HLVisitElements ($el, $TagName = "", $AttributeName = "", $AttributeValue = "", $depth = 0)  Return Array of elements in a DOM that meets specified criteria. (required: #include <HtmLayout UDF.au3>)
_HLSelectElements ($el, $CssSel)  Return Array of elements in a DOM that meets specified CSS selectors. (required: #include <HtmLayout UDF.au3>)
_HLSelectParent ($el, $CssSel, $depth = 0)  Find parent of the element by CSS selector. (required: #include <HtmLayout UDF.au3>)
_HLSetElementHtml ($el, $html, $where)  Set inner or outer html of the element. (required: #include <HtmLayout UDF.au3>)
_HLDeleteElement ($el)  Delete element. (required: #include <HtmLayout UDF.au3>)
_HLWindowAttachEventHandler ($hwnd, $func)  Attach/Detach ElementEventProc to the htmlayout window. (required: #include <HtmLayout UDF.au3>)
_HLGetParam ($ev, $prm)  Get parameter of events (required: #include <HtmLayout UDF.au3>)

HtmLayout UDF.7z

Edited by GMib
Link to comment
Share on other sites

Definitely cool and thanks for sharing.

I'm quite interested in exploiting the potential for this script, but I'm finding it hard to follow.

I left playing with the script for last, as I want to understand how it works. I was able to run "HtmLayout func ex.au3", and followed the script up to attaching an event. See if I got this right:

1.- The _events function polls events listed in the "HtmLayout Constants.au3" file.

2.- Events are checked agains the $ad[0] element of the array from _HLGetParam($ev,$prm). At this point we can match events like link clicks to elements. Two immediate questions come to mind: a) can we track the element that triggered the evt by name/id, or do we track it by index in the collection? :idea: Can element attributes be modified dynamically? I was thinking, once the evt is triggered, modifying the attributes of the element (i.e., color, positioning, etc), analogous to the js event models (onmousedown, onkeyup, etc).

Again, thanks and keep it up.

Other comments

----------------------

The "HtmLayout Ev ex.au3" includes the <perso.au3> library. First time I see it, searched the forums and found nothing.

Link to comment
Share on other sites

1.- The _events function polls events listed in the "HtmLayout Constants.au3" file.

_HLWindowAttachEventHandler($HLHwnd, "_events", $HANDLE_BEHAVIOR_EVENT+$HANDLE_MOUSE) trigger behavior event and mouse event, first parameter of _events function is the event triggered ($HANDLE_MOUSE if you click on htmlayout)

Each event are different parameter _HLGetParam get an array of parameter, see header of _HLGetParam for see array return.

_HLWindowAttachEventHandler($HLHwnd, "_events", $HANDLE_BEHAVIOR_EVENT+$HANDLE_MOUSE)

Func _events($ev, $prm)
    If $ev = $HANDLE_MOUSE Then
        $ad =  _HLGetParam($ev,$prm)
        ConsoleWrite("MOUSE_EVENTS: "&$ad[0]&@CRLF)
        ConsoleWrite("X pos: "&$ad[2]&@CRLF)
        ConsoleWrite("Y pos: "&$ad[3]&@CRLF)
    EndIf
    If $ev = $HANDLE_BEHAVIOR_EVENT Then
        $ad = _HLGetParam($ev,$prm)
        If $ad[0] = $HYPERLINK_CLICK Then
            $href = _HLGetAttributeByName($ad[1], "href")
            If $href = "close" Then Exit
        EndIf
    EndIf
EndFunc

2. Two immediate questions come to mind: a) can we track the element that triggered the evt by name/id, or do we track it by index in the collection? :idea: Can element attributes be modified dynamically? I was thinking, once the evt is triggered, modifying the attributes of the element (i.e., color, positioning, etc), analogous to the js event models (onmousedown, onkeyup, etc).

For get name tag of element triggered try _HLGetElementType($el)

for get id attribute _HLGetAttributeByName($el, "id")

for set css : _HLSetStyleAttribute ($el, $StyleName, $StyleValue)

Other comments

----------------------

The "HtmLayout Ev ex.au3" includes the <perso.au3> library. First time I see it, searched the forums and found nothing.

sorry, i'hve corrected.
Link to comment
Share on other sites

_HLWindowAttachEventHandler($HLHwnd, "_events", $HANDLE_BEHAVIOR_EVENT+$HANDLE_MOUSE) trigger behavior event and mouse event, first parameter of _events function is the event triggered ($HANDLE_MOUSE if you click on htmlayout)

Each event are different parameter _HLGetParam get an array of parameter, see header of _HLGetParam for see array return.

_HLWindowAttachEventHandler($HLHwnd, "_events", $HANDLE_BEHAVIOR_EVENT+$HANDLE_MOUSE)

Func _events($ev, $prm)
    If $ev = $HANDLE_MOUSE Then
        $ad =  _HLGetParam($ev,$prm)
        ConsoleWrite("MOUSE_EVENTS: "&$ad[0]&@CRLF)
        ConsoleWrite("X pos: "&$ad[2]&@CRLF)
        ConsoleWrite("Y pos: "&$ad[3]&@CRLF)
    EndIf
    If $ev = $HANDLE_BEHAVIOR_EVENT Then
        $ad = _HLGetParam($ev,$prm)
        If $ad[0] = $HYPERLINK_CLICK Then
            $href = _HLGetAttributeByName($ad[1], "href")
            If $href = "close" Then Exit
        EndIf
    EndIf
EndFunc

For get name tag of element triggered try _HLGetElementType($el)

for get id attribute _HLGetAttributeByName($el, "id")

for set css : _HLSetStyleAttribute ($el, $StyleName, $StyleValue)

sorry, i'hve corrected.

Thanks for clarifying. I'm surprized this script hasn't yet cought the attention it deserves. I'm going to start playing with it now.
Link to comment
Share on other sites

This sounds so awesome!

But I can't get it to work...

I placed HtmLayout Constants.au3 and HtmLayout UDF.au3 in the includes folder of AutoIt and downloaded the files from http://www.terrainformatica.com/htmlayout/ and placed them in the scriptdir. But whenever I try to open an .htm file I get the error shown in the attachment.

I think I need to copy the dll to some location, but don't know where or is it something else?

Could you please help me?

Thanks in advance,

Rawox.

post-40706-1272455696509_thumb.png

Link to comment
Share on other sites

I placed HtmLayout Constants.au3 and HtmLayout UDF.au3 in the includes folder of AutoIt and downloaded the files from http://www.terrainformatica.com/htmlayout/ and placed them in the scriptdir. But whenever I try to open an .htm file I get the error shown in the attachment.

dll must be in the same dir that HtmLayout UDF.au3 if you use exemple, else you can use _HLStartup($pathToDll)

Link to comment
Share on other sites

Never, ever, copy scripts to the AutoIt includes directory. That's not for your stuff, that's for AutoIt related standard UDFs.

Unzip your own stuff to your desktop, to c:\Myjunk, or some other folder that's entirely your own. Then run it as is, don't try to organize it into some other scheme. It would probably be good for you to reinstall the latest version of AutoIt, on the off chance you've overwritten something in the standard directory.

Link to comment
Share on other sites

I copied the dll to the same dir (autoit3/includes) but i still get the error...

sorry, i've just test and the dll must be in scriptdir, test with all file in the same dir (don't forget layout.htm)
Link to comment
Share on other sites

You have to run as x86 (32bit), not x64.

Then the executed script and the DLL have to be in the same directory (or the DLL must be in the %PATH%)

Additionally, the examples from htmlayout have to be in a subfolder of the scriptdir.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well,

I don't exactly know why but it's fixed :idea:.

I redownloaded the dll and opened the script in SciTE instead of clicking the file directly and now it works.

Let's experiment with this!

Thanks for this awesome stuff! :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...