WBGet function

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 5435
Joined: 19 Dec 2016, 01:58
Location: UK

WBGet function

12 Nov 2017, 16:10

- I'm placing the WBGet function here, in a location that's easy to find, and easy to copy and paste from.
- Also, if WBGet needs to be updated at some point, it can be posted here.

AHK v1 function:

Code: Select all

;[WBGet function for AHK v1.1]
;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
AHK v2 function:

Code: Select all

;[WBGet function for AHK v2]
;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

WBGet(WinTitle:="ahk_class IEFrame", Svr:=1)
{
	static msg := DllCall("user32\RegisterWindowMessage", Str,"WM_HTML_GETOBJECT", UInt)
	, IID := "{0002DF05-0000-0000-C000-000000000046}" ;IID_IWebBrowserApp
	;, IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ;IID_IHTMLWindow2
	lResult := SendMessage(msg, 0, 0, "Internet Explorer_Server" Svr, WinTitle)
	if (lResult != "")
	{
		VarSetCapacity(GUID,16,0)
		if (DllCall("ole32\CLSIDFromString", WStr,"{332C4425-26CB-11D0-B483-00C04FD90119}", Ptr,&GUID) >= 0)
		{
			DllCall("oleacc\ObjectFromLresult", Ptr,lResult, Ptr,&GUID, UPtr,0, PtrP,pdoc)
			obj := ComObject(9,ComObjQuery(pdoc,IID,IID),1)
			ObjRelease(pdoc)
			return obj
		}
	}
}
==================================================

AHK v1 example:

Code: Select all

;WBGet example AHK v1.1

q:: ;internet explorer - get active window webpage title and url
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
MsgBox, % oWB.document.title "`r`n" oWB.document.url
oWB := ""
return
AHK v2 example:

Code: Select all

;WBGet example AHK v2
q:: ;internet explorer - get active window webpage title and url
hWnd := WinGetID("A")
oWB := WBGet("ahk_id " hWnd)
MsgBox(oWB.document.title "`r`n" oWB.document.url)
oWB := ""
return
==================================================

Source:
[WBGet function by jethrow]
Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
https://autohotkey.com/board/topic/4705 ... -tutorial/

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 34 guests