#162732 - 2006-06-01 08:43 PM
More VBS to KiX conversion fun...
|
pearly
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
|
|
|
|
#162734 - 2006-06-01 09:30 PM
Re: More VBS to KiX conversion fun...
|
NTDOC
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
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
   
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
|
|
|
|
#162745 - 2006-06-05 11:51 PM
Re: More VBS to KiX conversion fun...
|
pearly
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
|
|
|
|
#162747 - 2006-06-06 12:25 AM
Re: More VBS to KiX conversion fun...
|
pearly
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
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|