Open a popup window from a hidden window

362 Views Asked by At

I am developing a tool in VB.NET to automate some tasks of another application, however, I would like to do this in a hidden way. I open the editor and then, through ShowWindow (Editor, SW_HIDE), I hide its window.

The problem is that in this Editor there is a button for "Save As", which opens a popup window to put the Name and Click Save.

When the Editor is not hidden it works perfectly. However, when the Editor is hidden, the popup window does not load (I cannot find its handle).

Is it possible to somehow perform this task, preferably with the hidden popup window too?

Thanks in advance.

EDIT:

PS1: The "Save As" button is not possible to view in Spy ++, only when I use Inspect.

Seeking to understand the difference between them I found this post.

Reading this post I understood that UIA do not see hidden elements.

Spy ++ and Inspect screens

Any suggestions for my project?

Here's my code:

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

There are 0 best solutions below