Forum Discussion

nishay_patel's avatar
nishay_patel
Occasional Contributor
10 years ago
Solved

Modal User Forms to be on top of other windows.

I am running a test that has a modal form in it that pops up halfway through the test.  I am running it via TestExecute.  The problem is that whenever the modal form does show, it is never on top, alw...
  • AlexKaras's avatar
    10 years ago
    Hi Nish,



    The approach works for modal forms as well. The only thing is that you need to get a reference to the form first, then change its properties and only after that show it as modal one.

    E.g.:

    ...

      ' make the form to be opened on top of all other ones

      Set wUserForm = Sys.Process("Test*te").Window("TUserForm", UserForms.UFIssueParams.Caption, 1)

      Call MakeWindowAlwaysOnTop(wUserForm)



      ' Displays the form and processes dialog results

      Select Case UserForms.UFIssueParams.ShowModal

        Case mrOk:      ' The OK button was pressed

    ...





    ' Set the "AlwaysOnTop" style for a user form

    Function MakeWindowAlwaysOnTop(Window)

      MakeWindowAlwaysOnTop = Win32API.SetWindowPos(Window.Handle, HWND_TOPMOST, _

        0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

    End Function