Page 1 of 1 1
Topic Options
#162732 - 2006-06-01 08:43 PM More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
How do I convert this to KiX?

Code:
    Set objWinShell = CreateObject("Shell.Application")
Set objWindows = objWinShell.Windows
For varCount = 0 To objWindows.Count - 1
On Error Resume Next
If objWindows(varCount).Hwnd = varHwnd Then
Set objBrowserObject = objWindows(varCount)
If Err = 0 Then
Exit For
Else
Err = 0
End If
End If
Next


Top
#162733 - 2006-06-01 09:17 PM Re: More VBS to KiX conversion fun...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
What value is assigned to varHwnd ?
Top
#162734 - 2006-06-01 09:30 PM Re: More VBS to KiX conversion fun...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well as Shawn points out, don't think all of these are just conversions. Some might be calls or something.

Here is the general idea, but doubt it would work directly like this.

What are you trying to do?

Code:
$objWinShell = CreateObject("Shell.Application")
$objWindows = $objWinShell.Windows
For $varCount = 0 To $objWindows.Count - 1
If $objWindows($varCount).Hwnd = $varHwnd
$objBrowserObject = $objWindows($varCount)
If @ERROR = 0
Exit 0
Else
$Err = 0
EndIf
EndIf
Next


Top
#162735 - 2006-06-01 10:34 PM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
Thanks for responding guys.

varHwnd is an existing IE's handle.

What I'm trying to do is create an object and run through the list of all active browsers and hook onto the browser that has the window handle (varHwnd).

Here's a better picture of what I'm trying to convert :

Code:

Function HookActiveDoc() As Object
Dim Result As Integer
Dim objBrowserObject As Object, objWinShell As Object, objWindows As Object
Dim varCount As Variant, varHwnd As Variant
Dim objDoc As Object

Set objBrowserObject = Nothing
Set objWindows = Nothing
Set objWinShell = Nothing
Set objDoc = Nothing

'Start: Initialize.
'for testing purposes, assign varHwnd to an existing browser handle
varHwnd = 197378
Set objWinShell = CreateObject("Shell.Application")
Set objWindows = objWinShell.Windows
For varCount = 0 To objWindows.Count - 1
On Error Resume Next
If objWindows(varCount).Hwnd = varHwnd Then
Set objBrowserObject = objWindows(varCount)
If Err = 0 Then
Exit For
Else
Err = 0
End If
End If
Next
'End: Initialize.

If objBrowserObject Is Nothing Then
'objBrowserObject is nothing
Set HookActiveDoc = Nothing
Goto PurgeObj
End If

Set objDoc = objBrowserObject.Document
If objDoc Is Nothing Then
'objDoc is nothing
Set HookActiveDoc = Nothing
Goto PurgeObj
End If

Set HookActiveDoc = objDoc
PurgeObj:
Set objBrowserObject = Nothing
Set objWindows = Nothing
Set objWinShell = Nothing
Set objDoc = Nothing
End Function



This is how I converted the function (but took it out of the function) :

Code:

$varHwnd = 197378

$objWinShell = CreateObject("Shell.Application")
$objWindows = $objWinShell.Windows
If $objWindows = 0
? "objWindows is Nothing"
Sleep 5
Exit 1
EndIf
? "objWindows count : " + $objWindows.Count
For $varCount = 0 to $objWindows.Count - 1
If $objWindows($varCount).Hwnd = $varHwnd
$objBrowserObject = $objWindows($varCount)
If @ERROR = 0
$varCount = $objWindows.Count - 1
EndIf
EndIf
Next

If $objBrowserObject = 0
? "objBrowserObject is Nothing"
Sleep 5
Exit 1
EndIf

$objDoc = $objBrowserObject.Document



However it fails on

Code:
If $objWindows($varCount).Hwnd = $varHwnd



and gives the error message : "ERROR : unexpected command!"

Top
#162736 - 2006-06-01 10:50 PM Re: More VBS to KiX conversion fun...
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well don't really have time to debug it, but the var is not being filled with any names. It is 0 in my testing so far so it errors out on that line.

It could be erroring for other reasons as well, just don't have time right now to look at it further.

Code:
Break On
Dim $ADoc
$ADoc = HookActiveDoc()
'ERROR: ' + @ERROR + ' - ' + @SERROR ?
'ADOC: ' + $ADoc ?

Function HookActiveDoc()
Dim $Result
Dim $objBrowserObject, $objWinShell, $objWindows
Dim $varCount, $varHwnd
Dim $objDoc
$objBrowserObject = ""
$objWindows = ""
$objWinShell = ""
$objDoc = ""

;Start: Initialize.
;'for testing purposes, assign varHwnd to an existing browser handle
$varHwnd = 197378
$objWinShell = CreateObject("Shell.Application")
$objWindows = $objWinShell.Windows
'Create objWindows: ' + @ERROR ?
For $varCount = 0 To $objWindows.Count - 1
'COUNTING WINDOWS: ' + @ERROR ?
'VAR COUNT IS: ' + $varCount ?
If $objWindows($varCount).Hwnd = $varHwnd
$objBrowserObject = $objWindows($varCount)
EndIf
Next
;End: Initialize.

If $objBrowserObject = ""
;objBrowserObject is nothing
$HookActiveDoc = ""
EndIf
$objDoc = $objBrowserObject.Document
If $objDoc = ""
;'objDoc is nothing
$HookActiveDoc = ""
EndIf
$HookActiveDoc = $objDoc
EndFunction



Top
#162737 - 2006-06-01 10:58 PM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
$varCount is just an iterator if that's what you're referring to when you say 'var'. I'm erring at the same place you are. I tried replacing '(', ')' with square brackets, but still no change. This works fine in VBS. I just can't nail the problem with the conversion...
Top
#162738 - 2006-06-01 11:22 PM Re: More VBS to KiX conversion fun...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
You got to say this:

If $objWindows.Item($varCount).Hwnd = $varHwnd

Top
#162739 - 2006-06-02 01:25 AM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
Hmm why doesn't VBS need it?
Top
#162740 - 2006-06-02 01:31 AM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
Also how did easily identify this Shawn? I can't find the parent to child (object to collection to object to collection) relationship on MSDN or anywhere else. I wish MSDN shows you the treeview of the possible combinations...
Top
#162741 - 2006-06-02 02:10 AM Re: More VBS to KiX conversion fun...
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Are we converting a vbscript file or a Visual Basic app?
Top
#162742 - 2006-06-02 02:16 AM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
well...I'm using a VB-like app, but the code I posted above will work in VBS. I'm borrowing the source from a friend who has used it in VBS.
Top
#162743 - 2006-06-05 10:40 PM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
I was able to figure out the rest of the conversion, thanks guys.
Top
#162744 - 2006-06-05 10:59 PM Re: More VBS to KiX conversion fun...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Do you "figure out" how I "figured it out" ?
Top
#162745 - 2006-06-05 11:51 PM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
Not really...I just added 'Item' to places where it was failing and it eventually worked itself out

And through trial and error, I've learned how to pull div, input, table, and other control properties. But as I stated in another thread, I don't get how :

$objWinShell = CreateObject("Shell.Application")

Code:
$obj = $objWinShell.Windows.Item(1).Document.All.Tags("TABLE").Item(6).Rows(0).Cells(0).InnerText



comes together. How does one learn the parent/child relationship of this line of code? This line works, I just don't know how to develop it.

Top
#162746 - 2006-06-06 12:19 AM Re: More VBS to KiX conversion fun...
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
In this case, the MSDN Document Object model is your best source. You could try hacking things with a good typelib viewer, but the IE object model is particularly funky to decipher.
Top
#162747 - 2006-06-06 12:25 AM Re: More VBS to KiX conversion fun...
pearly Offline
Getting the hang of it
*****

Registered: 2004-02-04
Posts: 92
ok and I thought it was just me. it was initially confusing, but I'm moving along fairly well with the limited knowledge that I have. best part of all, i'm accessing the DOM objects with KiX!
Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.075 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org