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 t...
  • 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
    '-------------------------------------------------------------------------------