Internet Explorer: resize elements to fit window (e.g. AutoHotkey archived forum)

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

Internet Explorer: resize elements to fit window (e.g. AutoHotkey archived forum)

01 Sep 2017, 18:37

This is a script to resize elements that go beyond the right of the window. The archived AutoHotkey forum is used as an example.

Code: Select all

q:: ;internet explorer - navigate to url and zoom
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
vUrl := "https://autohotkey.com/board/topic/19483-machine-code-functions-bit-wizardry/"
oWB.navigate(vUrl)
while oWB.busy
	Sleep, 10
;OLECMDID_OPTICAL_ZOOM := 63 ;OLECMDEXECOPT_DONTPROMPTUSER := 2
oWB.ExecWB(63, 2, 150, 0) ;zoom 150%
oWB.document.parentWindow.scrollTo(0, 550)
Sleep, 3000 ;this sleep is so that you can visibly notice before v. after
vList := "post_body,author_info"
Loop, Parse, vList, % ","
{
	vEltClass := A_LoopField
	oElts := oWB.document.getElementsByClassName(vEltClass)
	Loop, % oElts.length
	{
		oElt := oElts[A_Index-1]
		oElt.style.width := "700px"
	}
}
oWB := oElts := oElt := ""
return

;==================================================

;Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
;https://autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/

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)
      }
   }
}
Last edited by jeeswg on 06 Dec 2018, 21:37, edited 2 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6642
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Internet Explorer: resize elements to fit window (e.g. AutoHotkey archived forum)

01 Sep 2017, 19:20

I've separated the script above, into two parts: navigate to a url, and, resize web elements.
I've also made it so that the web elements resize based on the zoom percentage.

Code: Select all

w:: ;internet explorer - navigate to url and zoom
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
vUrl := "https://autohotkey.com/board/topic/19483-machine-code-functions-bit-wizardry/"
oWB.navigate(vUrl)
while oWB.busy
	Sleep, 10
oWB.ExecWB(63, 2, 150, 0) ;zoom 150%
oWB.document.parentWindow.scrollTo(0, 550)
oWB := ""
return

q:: ;internet explorer - autohotkey archived forum - adjust element widths based on zoom percentage
WinGet, hWnd, ID, A
ControlGetPos,,, vCtlW, vCtlH, Internet Explorer_Server1, % "ahk_id " hWnd
oWB := WBGet("ahk_id " hWnd)
vLogicalXDPI := oWB.document.parentWindow.screen.logicalXDPI
vDeviceXDPI := oWB.document.parentWindow.screen.deviceXDPI
vZoomRatio := vDeviceXDPI / vLogicalXDPI
vEltW := (vCtlW-40) * (1/vZoomRatio)
vList := "post_body,author_info"
Loop, Parse, vList, % ","
{
	vEltClass := A_LoopField
	oElts := oWB.document.getElementsByClassName(vEltClass)
	Loop, % oElts.length
	{
		oElt := oElts[A_Index-1]
		oElt.style.width := vEltW "px"
	}
}
oWB := oElts := oElt := ""
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Delta Pythagorean, DRocks and 39 guests