反射终端仿真器 - 与 IE 集成

发布于 2024-07-14 19:48:28 字数 2242 浏览 6 评论 0原文

我正在尝试在反射终端模拟器中运行的遗留应用程序和在 IE 中运行的基于浏览器的应用程序之间实现一些集成。

我正在使用主机启动脚本,以便将维护和部署问题隔离到旧应用程序中。 所有脚本都将在旧版应用程序中生成,并使用转义序列传输到 Reflection。

我目前能够:

  1. 启动 IE
  2. 设置隐藏工具栏等选项
  3. 导航到 URL
  4. 将状态信息传输回旧版应用程序
  5. 等待旧版应用程序发出“关闭”信号
  6. 关闭 IE

以下是执行此操作的 VBA 代码


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = CreateObject("InternetExplorer.Application")
  objIE.ToolBar = false
  objIE.Navigate("http://www.google.com/")
  objIE.Visible = true
  Session.Transmit "OK" & CR
  Session.WaitForString "CLOSE", 0, rcAllowKeystrokes
  objIE.Quit
End Sub

:是脚本继续运行,直到它从旧应用程序获取关闭命令。

我想要做的是使用一个脚本来启动浏览器,然后使用另一个脚本来关闭它或将其重新用于另一个 URL。 但是,我一直无法找到一种方法来跨脚本调用保存对 IE 的引用。 将 objIE 声明为 Sub Main 之外的 Global 没有帮助。 Session 对象确实在脚本调用中持续存在,但它似乎没有可用于此目的的属性。 (Session 确实有一个 UserData 属性,但那是一个字符串,而不是一个对象。)

这是我想要做的一个示例:

脚本 1 - 打开 IE 和 IE。 保持打开状态:


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = CreateObject("InternetExplorer.Application")
  objIE.ToolBar = false
  objIE.Navigate("http://www.google.com/")
  objIE.Visible = true
  Session.Transmit "OK" & CR
End Sub

脚本 2 - 将原始 IE 窗口发送到新的 URL


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = FindOriginalIE()
  objIE.Navigate("http://www.stackoverflow.com/")
  Session.Transmit "OK" & CR
End Sub

脚本 3 - 关闭 IE


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = FindOriginalIE()
  objIE.Quit
  Session.Transmit "OK" & CR
End Sub

我不明白的部分是如何实现脚本 2 和 3 中使用的 FindOriginalIE() 函数。

我尝试使用 GetObject( ) 而不是 CreateObject(),但这让我无处可去。 GetObject() 不会打开新的 IE 窗口,也不会查找现有的 IE 窗口。 我怀疑这是因为我在 Citrix 下运行,但我不确定。

我现在唯一的线索是尝试使用 IE 的 hWND 重新连接到原始窗口,或者使用 DDE 而不是 OLE。 然而,我在这两个方面都没有太多运气,主要是因为缺乏文档。

所以,我的问题是:

  1. 我想做的事情是否可能 使用 OLE? 也就是说有没有办法 保持我对 IE 的处理 主机发起脚本调用?
  2. 我应该期望 GetObject() 起作用吗? 或者这是一个死胡同?
  3. 是否可以使用Win32 API 在主机启动的脚本中 使用 hWND 重新连接 IE?

非常感谢任何相关文章、示例代码或其他见解的链接。

I'm trying to implement some integration between a legacy app running in the Reflection Terminal Emulator and a browser-based app running in IE.

I'm using Host Initiated Scripts so that maintenance and deployment issues are isolated to the legacy app. All scripts will be generated in the legacy app and transmitted to Reflection using escape sequences.

I am currently able to:

  1. Launch IE
  2. Set options such as hiding toolbars
  3. Navigate to a URL
  4. Transmit status info back to the legacy app
  5. Wait for a "close" signal from the legacy app
  6. Close IE

Here's VBA code to do that:


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = CreateObject("InternetExplorer.Application")
  objIE.ToolBar = false
  objIE.Navigate("http://www.google.com/")
  objIE.Visible = true
  Session.Transmit "OK" & CR
  Session.WaitForString "CLOSE", 0, rcAllowKeystrokes
  objIE.Quit
End Sub

The problem with this is that the script continues to run until it gets the close command from the legacy app.

What I want to do is use one script to launch the browser, and another to either close it or re-use it for another URL. However, I haven't been able to find a way to save my reference to IE across script calls. Declaring objIE as Global outside Sub Main didn't help. The Session object does persist across script calls, but it doesn't appear to have a property that I can use for this purpose. (Session does have a UserData property, but that's a String, not an Object.)

Here's an example of what I'd like to do:

Script 1 - Open IE & Leave it Open:


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = CreateObject("InternetExplorer.Application")
  objIE.ToolBar = false
  objIE.Navigate("http://www.google.com/")
  objIE.Visible = true
  Session.Transmit "OK" & CR
End Sub

Script 2 - Send original IE window to a new URL


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = FindOriginalIE()
  objIE.Navigate("http://www.stackoverflow.com/")
  Session.Transmit "OK" & CR
End Sub

Script 3 - Close IE


Sub Main
  Dim CR as String
  CR = CHR$(rcCR)
  Dim objIE as Object
  Set objIE = FindOriginalIE()
  objIE.Quit
  Session.Transmit "OK" & CR
End Sub

The part that I can't figure out is how to implement the FindOriginalIE() function used in Scripts 2 and 3.

I tried using GetObject() instead of CreateObject(), but that got me nowhere. GetObject() won't open a new IE window, or find an existing one. I suspect this is because I'm running under Citrix, but I'm not sure.

My only leads right now are to try using IE's hWND to reconnect to the original window, or to use DDE instead of OLE. I haven't had much luck with either of those however, mainly because of a lack of documentation.

So, my questions are:

  1. Is what I'm trying to do possible
    using OLE? That is, is there a way
    to persist my handle to IE across
    host initiated script calls?
  2. Should I expect GetObject() to work,
    or is that a dead end?
  3. Is it possible to use the Win32 API
    in a host initiated script to
    re-connect to IE using hWND?

Any links to related articles, sample code, or other insights are greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临走之时 2024-07-21 19:48:28

AFAIK GetObject 只是不支持 InternetExplorer 对象。 然而,这还不是结束:) 许多其他方式你可以将它从 shell32 的 windows 集合中拉出来。 为了使示例代码(改编自上面链接中的代码)正常工作,您需要设置对以下内容的引用:

  1. Microsoft Internet 控件
  2. Microsoft HTML 对象库
  3. Microsoft Shell 控件和自动化

Public Sub RunMeFirst()
    Dim objIE As SHDocVw.InternetExplorer
    Set objIE = New SHDocVw.InternetExplorer
    objIE.Visible = True
    objIE.navigate "http://www.google.com/"
    Do Until objIE.readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
End Sub

公共子 RunMeSecond() Dim objIE As SHDocVw.InternetExplorer 昏暗的文档作为 MSHTML.HTMLDocument 设置 objIE = GetIEByURL("http://www.google.com/") 设置 doc = objIE.document MsgBox doc.body.innerText End Sub

Private Function GetIEByURL(ByVal URL As String) As SHDocVw.InternetExplorer 将 objShell 调暗为 Shell32.Shell 将 objExplorer 调暗为 Shell32.ShellFolderView 将 obj 调暗为对象 设置 objShell = 新外壳 对于 objShell.Windows 中的每个 obj 如果 TypeOf obj 是 SHDocVw.InternetExplorer 那么 如果 StrComp(obj.LocationURL, URL, vbTextCompare) = 0& 然后 退出对于 万一 万一 下一个对象 设置 GetIEByURL = obj End Function

我认为可能值得讨论一下您想要完成的任务。 机器人化 IE 是一种相当笨拙的方法(我经常对此感到内疚),但可能有一种更好、资源消耗更少的方法。

AFAIK GetObject is just not supported for the InternetExplorer object. However this is not the end:) Among many other ways you can yank it out of the windows collection of shell32. For the example code (adapted from code in the link above) to work you need to set a reference to the following:

  1. Microsoft Internet Controls
  2. Microsoft HTML Object Library
  3. Microsoft Shell Controls and Automation

Public Sub RunMeFirst()
    Dim objIE As SHDocVw.InternetExplorer
    Set objIE = New SHDocVw.InternetExplorer
    objIE.Visible = True
    objIE.navigate "http://www.google.com/"
    Do Until objIE.readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
End Sub

Public Sub RunMeSecond() Dim objIE As SHDocVw.InternetExplorer Dim doc As MSHTML.HTMLDocument Set objIE = GetIEByURL("http://www.google.com/") Set doc = objIE.document MsgBox doc.body.innerText End Sub

Private Function GetIEByURL(ByVal URL As String) As SHDocVw.InternetExplorer Dim objShell As Shell32.Shell Dim objExplorer As Shell32.ShellFolderView Dim obj As Object Set objShell = New Shell For Each obj In objShell.Windows If TypeOf obj Is SHDocVw.InternetExplorer Then If StrComp(obj.LocationURL, URL, vbTextCompare) = 0& Then Exit For End If End If Next obj Set GetIEByURL = obj End Function

I think it might be worth discussing what you are trying to accomplish though. Roboting IE is a pretty kludgey approach (of which I am often guilty), but there might be a better, less resource intensive way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文