So I've been reading and reading and reading and learning and learning and learning, but I still have very little clue what I'm doing. I manage to get some things to work, but I'm not entirely sure why.
A few months ago, ahklerner made
this post, where he illustrated an example of using a browser control with tabs.
The next post in the thread is Jero3n translating ahklerner's script to be used with IE.ahk (as opposed to IEcontrol.ahk). However Jero3n's script didn't work.
As I'm trying to use a browser control in a tab with IE.ahk, I started poking around the two scripts. The big difference seemed to be the magic gethostwindow() function ahklerner was using.
I looked at IE.ahk and IEcontrol.ahk (the latter has the gethostwindow() function), and found that IE.ahk was using COM_AtlAxGetContainer(pwb) in a directly analagous way to how IEcontrol.ahk was using gethostwindow(). Ok, I thought, let me try it.
So I did. And it worked! (Working script below) But I still have no idea what it's doing. For example, I use it all the time, but I don't know what "pwb" means in these scripts. I have a general for what window handles are and how they work, but "pwb"s baffle me. I'm getting kind of tired of not understanding why my scripts work.
I'm just frustrated, because thought I'm good at seeing patterns and putting together high-level implementations of stuff, I would like to understand what's really happening rather than my trial and error method of creating scripts that utilize these really interesting bits of lower-level code that, to me, for all intents and purposes, are effectively magic.
Anyway, here's my working code (really, a cleaned up version of ahklerner+Jero3n's code, using the COM_AtlAxGetContainer function), in case anybody else would like to see a way to use browser controls in tabs with IE.ahk:
Code:
; needs IE.ahk in standard library
; http://www.autohotkey.com/forum/topic19225.html
OnExit, WebTerminate
SetTitleMatchMode, 2
W := 640
H := 480
Gui +0x2000000 +Lastfound
Gui Margin, 0, 0
Gui, Add, Tab, h25 w%W% gMyTab vSelTab, IE1|IE2
Gui, Show, h%H% w%W%, IE.ahk tabtest
GoSub, WebInit
Return
WebInit:
IE_Init()
pwb1 := IE_Add(WinExist(), 0, 25, w, h - 25)
pwb2 := IE_Add(WinExist(), 0, 25, w, h - 25)
IE_LoadURL(pwb1, "http://www.google.com")
IE_LoadURL(pwb2, "http://www.yahoo.com")
OldhWnd := IE1 := COM_AtlAxGetContainer(pwb1)
IE2 := COM_AtlAxGetContainer(pwb2)
Return
MyTab:
Gui, Submit, NoHide
WinHide, % "ahk_id " . OldhWnd
WinShow, % "ahk_id " . %SelTab%
OldhWnd := %SelTab%
return
GuiClose:
WebTerminate:
Gui, Destroy
COM_Release(pwb)
IE_Term()
ExitApp