Forum Discussion

vladd1's avatar
vladd1
New Contributor
3 months ago
Solved

Need to verify cursor state on disabled button

Thank you for whoever helps to start,

The issue I am seeing is running a disabled check on a button in my application. Unfortunately our team believes the best way to check the code we have to work with is to check the pointer-event, which remains: none. I am struggling to locate the cursor object whether inside Sys.Browser, Sys.Window, WndObjcect.

I have found the cursor documentation but I am unsure how to get the 'componentObj' needed for the property check. I also see tObjectPicker and have name mapped the object I hover the mouse over, but the properties pickedObjectName and cursor return failures in my script.

I am working in circles it seems, please help.

 

  • Hello vladd1,

    I think I know what you are struggling with. 

    You may have this doc which explains settings the various cursor states....
    https://support.smartbear.com/testcomplete/docs/reference/user-forms/properties/cursor.html

    The button likely has a .cursor property however.

    var form = UserForms.SampleForm;
    var button = form.buttonOK;
    
    // Moves the cursor to the button center
    button.MouseMove();
    
    //Returns the cursor type
    var currentCursor = button.Cursor;
    Log.Message("Cursor type: " + currentCursor);

    This code reads the current cursor type and logs it. The value returned will be one of the cr* constants (like crDefault, crHandPoint, etc.).

    ... If you find my posts helpful drop me a like! πŸ‘ Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

7 Replies

  • scot1967's avatar
    scot1967
    Icon for Champion Level 2 rankChampion Level 2

    Hello vladd1,

    I think I know what you are struggling with. 

    You may have this doc which explains settings the various cursor states....
    https://support.smartbear.com/testcomplete/docs/reference/user-forms/properties/cursor.html

    The button likely has a .cursor property however.

    var form = UserForms.SampleForm;
    var button = form.buttonOK;
    
    // Moves the cursor to the button center
    button.MouseMove();
    
    //Returns the cursor type
    var currentCursor = button.Cursor;
    Log.Message("Cursor type: " + currentCursor);

    This code reads the current cursor type and logs it. The value returned will be one of the cr* constants (like crDefault, crHandPoint, etc.).

    ... If you find my posts helpful drop me a like! πŸ‘ Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

  • JDR2500's avatar
    JDR2500
    Frequent Contributor

    First, I'm not 100% sure what you are trying to accomplish, so sorry if my response is off target.   

    Years ago I dabbled with identifying the current cursor type (e.g. Arrow, Move, Etc.) and ended up using the Win32API.  I was semi-successful accomplishing what I had in mind, but eventually took a different approach. 
    The below code (VBScript) shows what I did to get the cursor object.  I passed this Function the application window object and got back the cursor object.

    I can't recall if that ended up working as I intended.  I think I was on the right path with the Win32API though.

    Function getCurrentCursor(wndObj)
      Dim pid, tid, crsr     
      pid = Win32API.GetWindowThreadProcessId(wndObj.Handle, Nothing)
      tid = Win32API.GetCurrentThreadId
      Call Win32API.AttachThreadInput(pid, tid, True)
      crsr = Win32API.GetCursor
      Call Win32API.AttachThreadInput(pid, tid, False)
      getCurrentCursor = crsr
    End Function

     

  • I assume you are trying to validate the cursor as a work around to finding button state. If I understand it correctly your goal is to check if your application button is disabled and I suggest you have a read https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/onscreen/enabled-property-onscreen-object.html

    πŸ’¬ If a response helped you out, don’t forget to Like it! And if it answered your question, mark it as the solution so others can benefit too.

     

    • Hassan_Ballan's avatar
      Hassan_Ballan
      Icon for Champion Level 3 rankChampion Level 3

      TestComplete provides access to the cursor object via Sys.Desktop.Cursor, which allows you to identify the current mouse cursor shape by analyzing the cursor handle.

      function GetCursorHandle() {
        var cursor = Sys.Desktop.Cursor;
        Log.Message("Cursor Handle: " + cursor.Handle);
      }
      

      You may also need to run Cursor.ToString() to save those handle values.

      πŸ’¬ If a response helped you out, don’t forget to Like it! And if it answered your question, mark it as the solution so others can benefit too.

      • scot1967's avatar
        scot1967
        Icon for Champion Level 2 rankChampion Level 2

        Yeah, this could likely be be found at the app level as well.  Simpler if that action isn't specially tied to the button object.  Nice.

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    What test are you trying to perform - verifying that the button is disabled? Or verifying that the cursor has changed upon hovering over the disabled button? Or verifying that the button can not be moved?

    You mentioned "TObjectPicker", is your application developed using Delphi?

  • Hi vladd1​!

    Do any of the solutions, provided by everyone here, help with what you are trying to build? If not, could you further elaborate on the scenario you are trying to accomplish with TestComplete? 

    Thanks!