====== HTMLFile ======
//Original post by [[user:jethrow]] on the [[https://www.autohotkey.com/board/topic/56987-com-object-reference-autohotkey-v11/#entry358974|AutoHotkey Archived Forums]].//
----
**Object Name:** ''HTMLFile''
**Purpose:** Represents an HTML document. Can be used to read, write, & interact with HTML.
**Documentation Link** ((Microsoft stopped hosting [[http://msdn.microsoft.com/en-us/library/ms535862|their documentation]] for this object in 2017. The last archive.org archive of the page can be found [[https://web.archive.org/web/20160817074457/https://msdn.microsoft.com/en-us/library/ms535862|here]]. All of Microsoft's links have been modified to redirect to [[https://developer.mozilla.org/en-US/docs/Web/API/Document|Mozilla's generic "Document" documentation]].))
**Other Links:** [[http://www.w3schools.com/jsref/dom_obj_document.asp|W3Schools - Document Object]]
**Basic Code Example** - this example extracts all the text & URLs from the links on the Google Search Page:
;// download the webpage source
URLDownloadToFile, http://www.google.com, Google_HTML
FileRead, html, Google_HTML
FileDelete, Google_HTML
;// write the Google Source to an HTMLfile
document := ComObjCreate("HTMLfile")
document.write(html)
;// loop through all the links
links := document.links
while (A_Index<=links.length, i:=A_Index-1)
list .= i ") " links[i].innerText "`nURL: " links[i].href "`n`n"
;// some URLs have "about:" rather than the domain
StringReplace, list, list, about:, http://www.google.com, All
MsgBox, %list%
This next example shows how an HTMLfile object* can be used to create an HTML Control:
color := HtmlBgColor()
;// HTML to be added to a GUI:
html =
(
text color example
)
;// create a simple GUI
Gui, Add, Button, x6 y60 w55 h20, Red
Gui, Add, Button, x71 y60 w55 h20, Blue
Gui, Add, ActiveX, x0 y-5 w140 h50 vdocument, HTMLFile
document.write(html)
Gui, Show, x399 y246 w138 h86, HTML
return
GuiClose:
Gui, Destroy
ExitApp
ButtonRed:
ButtonBlue:
document.all("id").style.color := SubStr(A_ThisLabel,7)
return
HtmlBgColor() {
Format := A_FormatInteger
SetFormat, IntegerFast, Hex
color := SubStr(DllCall("GetSysColor", "int",15),3)
SetFormat, IntegerFast, %Format%
return SubStr(color,5,2) SubStr(color,3,2) SubStr(color,1,2) ;// switch from BGR -> RGB
}
*Note - the HTMLfile object isn't required to accomplish this. You could simply write the HTML when adding the ActiveX Control:
Gui, Add, ActiveX, x0 y-5 w140 h50 vDocument, MSHTML:%html%
[[http://www.autohotkey.com/board/topic/55133-flashhtml-in-gui/#entry346213|This post]] has an example of a completely HTML based GUI.