从隐藏的窗口中打开弹出窗口

时间:2020-04-25 16:41:46

标签: vb.net winapi hide showwindow

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

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

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

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

谢谢。

编辑:

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

我试图在this帖子中找到他们之间的区别。

阅读this帖子后,我了解到UIA看不到隐藏的元素。

Spy ++ and Inspect screens

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

这是我的代码:

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

0 个答案:

没有答案