Sign in to follow this  
Followers 0
duckling78

How get width/height of embedded IE control?

3 posts in this topic

I want to get the position of an embedded IE control (either relative to the screen or relative to the window is ok).

ControlGetPos on the return value from _IECreateEmbedded seems to work at the start, but if I click on any other control (such as the label in the example) it returns the position and size of the label instead of the IE control. What's happening? muttley

ControlGetPos returns 0 for the controlID from the return value of GUICtrlCreateObj($oIE, 10, 40, 620, 400). Why doesn't ControlGetPos on $GUIActiveX below return an array that has the position and size of the control? Is $GUIActiveX not the correct controlID I'm supposed to be using?

Here is an example script:

#include <GUIConstants.au3>
#include <IE.au3>

Opt("GUIOnEventMode", 1)

Local $winTitle = @ScriptName

Local $gui = GUICreate($winTitle, 640, 480, default, default, BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_MINIMIZEBOX)) ;$WS_POPUP,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW = 136
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "WindowResized")
GUISetOnEvent($GUI_EVENT_RESTORE, "WindowResized")
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "WindowResized")
GUISetOnEvent($GUI_EVENT_RESIZED, "WindowResized")

Local $oIE = _IECreateEmbedded()

Local $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 620, 400)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

_IENavigate($oIE, "http://www.autoitscript.com")
_IELoadWait($oIE, 100, 5000)

Local $lbl = GUICtrlCreateLabel(LabelText(), 10, 4, 600, 30)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

GUISetState()

While 1
    Sleep(50)
WEnd

Func LabelText()
    $pos = ControlGetPos($winTitle, "", $oIE)
    
    If IsArray($pos) Then
        Return "Click this text and then resize the window.  Notice the values are for the last selected control, not the IE control." & @CRLF & _
        "ControlGetPos($winTitle, "", $oIE) return values: " & $pos[0] & ", " & $pos[1] & ", " & $pos[2] & ", " & $pos[3]
    Else
        Return "ControlGetPos did not return an array.  @error = " & @error
    EndIf
EndFunc

Func WindowResized()
    GUICtrlSetData($lbl, LabelText())
EndFunc

Func ExitScript()
    Exit
EndFunc

Share this post


Link to post
Share on other sites



This cleaned up version works fine for me:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Opt("GUIOnEventMode", 1)

Global $winTitle = @ScriptName
Global $gui = GUICreate($winTitle, 640, 480, Default, Default, BitOR($WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_MINIMIZEBOX));$WS_POPUP,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW = 136
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitScript")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "WindowResized")
GUISetOnEvent($GUI_EVENT_RESTORE, "WindowResized")
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "WindowResized")
GUISetOnEvent($GUI_EVENT_RESIZED, "WindowResized")

Global $oIE = _IECreateEmbedded()

Global $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 620, 400)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)

_IENavigate($oIE, "http://www.autoitscript.com")
_IELoadWait($oIE, 100, 5000)

Global $lbl = GUICtrlCreateLabel("Click this text and then resize the window." & @CRLF & "Notice the values are for the last selected control, not the IE control.", 10, 4, 600, 30)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

GUISetState()

While 1
    Sleep(50)
WEnd

Func LabelText()
    Local $pos = ControlGetPos($winTitle, "", $oIE)

    If IsArray($pos) Then
        TrayTip("LabelText()", "$pos is an array: " & $pos[0] & ", " & $pos[1] & ", " & $pos[2] & ", " & $pos[3], 5)
        Return "ControlGetPos($winTitle, "", $oIE) return values: " & $pos[0] & ", " & $pos[1] & ", " & $pos[2] & ", " & $pos[3]
    Else
        TrayTip("LabelText()", "$pos is not an array", 5)
        Return "ControlGetPos did not return an array.  @error = " & @error
    EndIf
EndFunc  ;==>LabelText

Func WindowResized()
    GUICtrlSetData($lbl, LabelText())
EndFunc  ;==>WindowResized

Func ExitScript()
    Exit
EndFunc  ;==>ExitScript

The fact that you were able to run your version without #include <WindowsConstants.au3> proves you are using an out-of-date version of AuotIt. Download AutoIt 3.2.12.1 at least.

It is a little strange that you have to use $oIE instead of $GUIActiveX in ControlGetPos(), because I think the Control ID should have worked too.

muttley


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Ahhh, I was using AutoIt3 version 3.2.10.0. I tried using Beta 3.2.11.7 and it worked... Argh must have been a bug in the previous version?

Anyways I should update my AutoIt3 I guess sorry all muttley

Share this post


Link to post
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
Sign in to follow this  
Followers 0