Forum Discussion

luisanillo's avatar
luisanillo
Occasional Contributor
5 years ago
Solved

Focus on window not visible on screen

Hello,

 

I'm testing an application (delphi) and every time I press F12, I get a new window which helps me navigate in the application (note that both the application and the window are part of the same process, which is why minimizing does not show the window). My issue is that when it is done enough times, the window appears behind the application. From what the devs told me, I have to change the window Z order to make it visible on screen.  

 

I have tried multiple things, but the object always says visible = true, while visibleOnScreen = false. Any idea how can I change the z order of application windows or even better, make my window visible again ?

  • AlexKaras's avatar
    AlexKaras
    5 years ago

    Well, I see...

     

    Ages ago I used this function (VBScript) to put on top some form. (Actually - window registered in Windows.) Hope, it might inspire you with some ideas.

    '-------------------------------------------------------------------------------
    
    Sub ActivateForm(ByVal strClassName, ByVal strWindowTitle)
      Const cProcName = "ActivateForm(): "
    
      Dim hWnd
      Dim dwLastError
    
      hWnd = Win32API.FindWindow(strClassName, strWindowTitle & " [Shared]")
      If (0 = hWnd) Then
        hWnd = Win32API.FindWindow(strClassName, strWindowTitle & " [Personal]")
        If (0 = hWnd) Then
          Log.Error cProcName & "Window was not found", "Window class name: " & strClassName & _
              vbCrLf & "Window title: " & strWindowTitle
        End If
      End If
    '  If (0 = Win32API.BringWindowToTop(hWnd)) Then
      If (0 = Win32API.SetWindowPos(hWnd, Win32API.HWND_TOPMOST, 0, 0, 0, 0, Win32API.SWP_NOSIZE)) Then
        dwLastError = Win32API.GetLastError()
        Log.Error cProcName & "Window was not activated.", "Window class name: " & strClassName & _
            vbCrLf & "Window title: " & strWindowTitle & vbCrLf & _
            "System error code: " & dwLastError & vbCrLf & "System error message: " & _
            Utilities.SysErrorMessage(dwLastError)
      End If
    End Sub
    '-------------------------------------------------------------------------------
    

     

9 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    windowObject.Activate where "windowObject" is your window you want to bring forward.

     

    See if that helps.

    • luisanillo's avatar
      luisanillo
      Occasional Contributor

      Sadly it does not, I have already tried Activate, SetFocus, Minimize/Maximise and no success.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Activate should work.. that is, essentially, the command that brings a window within an application forward.  

         

        So... setting aside my TestComplete hat and putting on my QA/Tester hat...

         

        Does it always happen at the same place?

        You say you use it to navigate.  What if you navigate to that place where it fails right away rather than several times through?  Does it "fail" then, too?

         

        See... my suspicious b*****d of a brain is wondering if this isn't a problem in your AUT where some form or other is set in such a way that it is ALWAYS in front, regardless of what else is happening.