首页 > 解决方案 > 从隐藏窗口打开弹出窗口

问题描述

我正在 VB.NET 中开发一个工具来自动化另一个应用程序的一些任务,但是,我想以一种隐藏的方式来做这件事。我打开编辑器,然后通过ShowWindow (Editor, SW_HIDE)隐藏它的窗口。

问题是在这个编辑器中有一个“另存为”按钮,它会打开一个弹出窗口来放置名称并单击保存。

当编辑器未隐藏时,它可以完美运行。但是,当编辑器被隐藏时,弹出窗口不会加载(我找不到它的句柄)。

是否有可能以某种方式执行此任务,最好也使用隐藏的弹出窗口?

提前致谢。

编辑:

PS1:只有当我使用 Inspect 时,才能在 Spy ++ 中查看“另存为”按钮。

为了了解它们之间的区别,我找到了这篇文章。

阅读这篇文章,我了解到 UIA 看不到隐藏元素。

Spy ++ 和检查屏幕

对我的项目有什么建议吗?

这是我的代码:

Private Sub AtualizarGrafico()

Dim nomejanela As String = ""
    For Each p As Process In System.Diagnostics.Process.GetProcesses
        If (p.MainWindowTitle <> "") Or (p.MainWindowTitle <> " ") Then
            If Mid(p.MainWindowTitle, 1, 9) = "ProfitPro" Then
                nomejanela = p.MainWindowTitle
            End If
        End If
    Next

    If FindWindow(vbNullString, nomejanela) = False Then
        MsgBox("A Plataforma não está aberta.")
        Exit Sub

    End If

    Dim Profit As Integer = FindWindow(vbNullString, nomejanela) 'LEVEL 1
    Dim Container As Integer = Win32.FindWindowEx(Profit, vbNullString, "MDIClient", vbNullString) 'LEVEL 1.1
    Dim Editor As Integer = Win32.FindWindowEx(Container, vbNullString, "TLanguageEditorForm", vbNullString) ' LEVEL 1.1.1

    Win32.ShowWindow(Editor, Win32.SW_HIDE)
    Win32.SetForegroundWindow(Container)
    Win32.SendMessage(Container, Win32.WM_ACTIVATE, 0, 0)

    'Shortcut to open
    If Editor = 0 Then
        SendKeys.Send("^q")
    End If

    Dim EditorPainel As Integer = Win32.FindWindowEx(Editor, vbNullString, "TPanel", "EditorPanel") 'LEVEL 1.1.1.1
    Dim EditorIntraPainel As Integer = Win32.FindWindowEx(EditorPainel, vbNullString, "TPanel", "EditorInnerPanel") 'LEVEL 1.1.1.1.1.1
    Dim EditorEstrategia As Integer = Win32.FindWindowEx(EditorIntraPainel, vbNullString, "TLanguageEditor", "") 'LEVEL 1.1.1.1.1.1.1

    Dim Painel As Integer = Win32.FindWindowEx(Editor, Nothing, "TPanel", "") 'LEVEL 1.1.1.2
    Dim ToolBar As Integer = Win32.FindWindowEx(Painel, Nothing, "TTBToolBar", "ToolBar1") 'LEVEL 1.1.1.2.1

    'wait 'til load the form
    Thread.Sleep(1000)

    Win32.SetForegroundWindow(EditorEstrategia)
    Win32.SetActiveWindow(EditorEstrategia)

    SendKeys.SendWait("^{HOME}") '   
    SendKeys.SendWait("^+{END}") '  
    SendKeys.SendWait("{DEL}")
    SendKeys.SendWait("^v")

    'ROTINA PARA SALVAR

    'backSaveAs:
    Dim HandleBtnSalvarComo = AutomationElement.FromHandle(ToolBar)
    Dim FindSaveAs = HandleBtnSalvarComo.FindFirst(TreeScope.Children, New PropertyCondition(AutomationElement.NameProperty, "Salvar como..."))
    Dim btnSaveAs As InvokePattern = DirectCast(FindSaveAs.GetCurrentPattern(InvokePattern.Pattern), InvokePattern)
    btnSaveAs.Invoke()

    Thread.Sleep(1000)

    Dim windowSaveAs As Integer = Win32.FindWindow(vbNullString, "Salvar Como") 'LEVEL 2
    Dim fieldNameSaveAs As Integer = Win32.FindWindowEx(windowSaveAs, vbNullString, "TEdit", vbNullString) 'LEVEL 2.1

    'VARIÁVEL DO NOME DA ESTRATÉGIA
    Win32.SendMessageT(fieldNameSaveAs, Win32.WM_SETTEXT, 0, numero_editor & "EE")

    Dim HandleBtnSave = AutomationElement.FromHandle(windowSaveAs)
    Dim FindSave = HandleBtnSave.FindFirst(TreeScope.Children, New PropertyCondition(AutomationElement.NameProperty, "Salvar"))
    Dim btnSave As InvokePattern = DirectCast(FindSave.GetCurrentPattern(InvokePattern.Pattern), InvokePattern)
    Win32.ShowWindow(Editor, Win32.SW_SHOW)
    btnSave.Invoke()
End Sub

标签: vb.netwinapihideshowwindow

解决方案


推荐阅读