Forum Discussion

RLRE's avatar
RLRE
Occasional Contributor
5 years ago

How to change cursor to hourglass from a TestComplete Extension

I wrote a TestComplete extension to update Keyword-Test signature from TestComplete in to an external tool. However, this action takes very long time. That's why I need to change the cursor from arrow to hourglass, and back to arrow after action is done. (Using a try-catch-finaly, of course.)

The module doing the opperation is writen in js. However, my script extension contains vbs modules too and methods, I can successfully call from the js module. 
If I try to use the following code, suggested by TestComplete code completition in the vbs module:
Win32API.SetCursor(Win32API.IDC_WAIT);
I got the error "Object expected". I.e., the TestComplete extension does not know About Win32API object, despite the code completition suggestion, and despite the correct installation and activation of the win32api extension. (checked via File | Install extensions)
Ommiting the Win32API. prefix has similar effect. 

I did not found any aq*.* methods allowing changing the cursor.
SmartBears description on writing extentions seems to contain no hint about changing the cursor in a ScriptExtension. Please appologize, if I overlook it.

(PS: I am using an old TestComplete 10.60x Version; however, I guess, this is not the Point.)
Any suggestions are appreciated.

Thanx in advice for your F1!

  • Hi,

     

    The object does not support this property or method:  'dotNET.Cursors'

    Proper assembly must be added to dotNET Bridge in TestComplete in order for this or that .Net class to become accessible for dotNET TestComplete's object. Depending on the .Net version/flavor you are using the required assembly might differ. (For example, as per https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.cursors?view=netcore-3.1,

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Win32API object is not accessible from script extensions and I don't know any other way to change cursor but direct Win32 call that you mentioned.

    Two possible options that I can imagine at the moment:

    a) Wrap the code that sets cursor and calls a method from your script extension into one regular function in TestComplete and call this wrapping function but not script extension from your test code;

    b) Considering that dotNET object is accessible from script extension, check if .Net provides the means to change cursor shape.

     

    • RLRE's avatar
      RLRE
      Occasional Contributor

      Hi Alex,

      thank you for your response.

      Regarding (a)

      I am not sure, what you mean with "calls a method from your script extension into one regular function in TestComplete". Actually, I am trying to find adequate code for completing the following vbs sub:

      sub setHourglass(b)
         if b then
            ' set hourglass cursor
         else
            ' set arrow cursor
         end if
      end sub

      All the rest is done. (I mean, the code doing the job calls MyNamespace.setHourglass(true) before time-consuming operation and MyNamespace.setHourglass(false) after the operation in a try-catch-finally block properly.)

      Perhaps, you have a hint for me, how to go further in that direction.

      Regarding (b)

      The dotNet object contains a lot of properties. The only one I found via code completion, that seems to have something with cursor is

      dotNet.System.Console.set_CursorTop

      I expected some properties / methods for cursor below following namespace

      dotNet.System.Window

      However, the code completion does not offers it. 

      That means: we have still no solution 😞

      Perhaps, I overlook something. If you have a code example for me, please do not hesitate to share it with me. Thank you very much!

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Excuse me for been not clear enough.

        For a) I meant this:

        -- Create something like this as a regular reusable test code (i.e. the code in your test project, but not in a Script Extension):

        Sub CallLongProc

          setHourglass(True)

          MyNamespace.LongProcedureFromScriptExtension

          setHourglass(False)

        End Sub

        -- Call the above sub where needed.

         

        If you just like to implement setHourglass() function as a standalone one within your script extension, then this is not possible because Win32API object is not accessible from within script extensions.

        I should have somewhere my ages-old code 😉 that sets cursor to hourglass, but it is implemented with the use of win32 calls and thus cannot be ported to script extension.

         

        .Net:

        Something like this might help:

        https://stackoverflow.com/questions/1568557/how-can-i-make-the-cursor-turn-to-the-wait-cursor

        https://www.google.com/search?q=.net+change+cursor+to+hourglass

         

        (For the first link I would try something like dotNET.Cursor.Current = dotNET.Cursors.WaitCursor;)