Sign in to follow this  
Followers 0
tommytx

How do I attach to a running Gui or the html file loaded into the GUI?

7 posts in this topic

#1 ·  Posted (edited)

Gui Title = "Win 1"

htm Title = "Broker"

I have tried just about everything that I can think of to do this... to no avail.

I have a Gui running on the desktop with the title of "Win 1" and inside the gui is loaded an html file.

What I am trying to do is read the body of the html file and get it into my program..

While the Gui is running on my desktop I wrote and ran the below program... but it keeps coming back with a big fat Zero for the text that is on the screen of the GUI...

Any suggestions...

#include <IE.au3>

; $oIE = _IEAttach ("Win ")
; $sText = _IEBodyReadText ($oIE)
; MsgBox(0, "Body Text", $sText)

$oIE = _IEAttach ("Broker")
$sText = _IEBodyReadText ($oIE)
MsgBox(0, "Body Text", $sText)

So bottom line is it possible for one GUI to read another GUI specifically the html page running in the GUI and get data from it?

I have tried attaching to both the GUI title and the HTML file title and neither works...

Edited by tommytx

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here is more information that details exactly what I am trying to do.. if anyone is willing to look and help.

Below is the actual htm page that is loaded into the gui..

So here it is blow by blow.

This is the htm code that loads into GUI with the name Win 1.

The below html will be named 'test.htm' and will load into the simple GUI

This html file has a simple javascript counter that counts down from 20 to 0 then repeats.

This data is 'test.htm'

<title>Broker</title>
<script language="JavaScript" type="text/javascript">
var sec = 20;
var min = 00;
function countDown() {
   sec--;
  if (sec == -01) {
   sec = 20;
  }
time = '<h2>' + sec + ' counting for you.</h2>';
if (document.getElementById) { document.getElementById('theTime').innerHTML = time; }
SD=window.setTimeout("countDown();", 1000);
}
window.onload = countDown;
</script>
<span id="theTime" class="timeClass"></span>

This is code following is filename 'simplegui.au3' which is running on my desktop with the test htm file above loaded..It loads the test.htm file and displays a counter being run by the test.htm

The below data is 'simplegui.au3'
#include <IE.au3>
#include <GUIConstants.au3>
#include <GuiconstantsEx.au3>
Dim $hGUI, $oIE1
$hGUI = GUICreate('Win 1', 200, 200, -1, -1)
$oIE1 = ObjCreate("Shell.Explorer.2")
$Obj1_ctrl = GUICtrlCreateObj($oIE1, 2, 2, 190, 190)
GUISetState(@SW_SHOW)
_IENavigate($oIE1, @ScriptDir & "test.htm")

While 1
  $nMsg = GUIGetMsg()
Select
  Case $nMsg = $GUI_EVENT_CLOSE
  Exit
EndSelect
Sleep(100)
WEnd

And this is the below code is file name 'control.au3' that I am trying to get it to read the simple gui with the test.htm loaded. I actually want to read the counter that is being printed on the page... with the Id='theTime'

Some of the code I have tried to communicate with the GUI is shown below..

This code is named 'control.au3'
#include <IE.au3>
IF WinExists("Win 1") then MsgBox(0,"","Found The GUI Window.")
IF WinExists("Broker") then MsgBox(0,"","Found The HTML File.")
$oIE = _IEAttach ("Win 1")
$sText = _IEBodyReadText ($oIE)
MsgBox(0, "Attach to GUI", $sText)

$oIE = _IEAttach ("Win 1", "This is a test.")
$sText = _IEBodyReadText ($oIE)
MsgBox(0, "Attach to GUI window text", $sText)

$sText = _IEBodyReadHTML ($oIE)
MsgBox(0, "Attach to HTML in Win 1.", $sText)

$oIE = _IEAttach ("Broker")
$sText = _IEBodyReadHTML ($oIE)
MsgBox(0, "Attach to HTML file.", $sText)

So my bottom line is that I want to:

1. Run the simplegui.au3 on my desktop.

2. simplegui.au3 will load test.htm and display the counter with the id=theTime

3. I want to be able to load the controlgui.au3 and click a button and have it read the value of theTime on the simple gui.and display it as a Msgbox... for the time being..

As you can see above I have not tried to read the id=theTime yet since i have not yet been able to address the test.htm file in the simplegui.au3 at all so far.. so no need to worry about reading 'theTime' id until I can communicate with the test.htm file to begin with..

Edited by tommytx

Share this post


Link to post
Share on other sites

$oIE1 = ObjCreate("Shell.Explorer.2")

;;; $oIE1 is the object returned from objCreate(). This isn't string!!!

...

$Obj1_ctrl = GUICtrlCreateObj($oIE1, 2, 2, 190, 190)

GUISetState(@SW_SHOW)

...

;;; $oIE1 is the object returned from objCreate(). This isn't string!!!

_IENavigate($oIE1, @ScriptDir & "\test.htm")

i think that is wrong to use

$oIE1 as first parameter of _IeNavigate(..) that requires a string or a string-variable

Share this post


Link to post
Share on other sites

i think that is wrong to use

$oIE1 as first parameter of _IeNavigate(..) that requires a string or a string-variable

Really? Because my help file says that _IENavigate takes an object variable as the first parameter, it doesn't mention strings anywhere in the description until the second parameter, which is the URL you want to navigate to.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You can use _IEAttach with the "embedded" option to interact with an embedded browser.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#include <IE.au3>

$oIE = _IEAttach ("Win 1", "embedded")

MsgBox(0, "The Title", _IEPropertyGet ($oIE, "title"))

Wow! Dale you are sooooo.... smart... it pulled the title word "Broker" right out of the embeded browser... now I am off to see if I can pull "theTime" from the counter.... it should work since it did recognize the "Title" of the htm file..

sorry to ask so many questions, but I am building a DOOZEY...

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hot diggetdy dog... pulled that sucker right out....all I did was ask for theTime... my first work with embedded but I like it already.

Thanks Dale you have been more help to me in the last month than all the other folks put together.... Thanks again....you must get very tired of all the dumb questions....

#include <IE.au3>
$oIE1 = _IEAttach ("Win 1", "embedded")
MsgBox(0, "The Title", _IEPropertyGet ($oIE1, "title"))

$oDiv = _IEGetObjById ($oIE1, "theTime")
msgbox(0,"",$oDiv.innerTEXT)

How do I mark this sucker answered? or is that for the moderator?

Edited by tommytx

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