Forum Discussion

suvidhshetty_1's avatar
suvidhshetty_1
Occasional Contributor
13 years ago

Unable to verify it the Check box is Checked or not in 'ListBox' type list.



Hi,


I am not able to verify if the check box is checked or not for ‘ListBox’ type lists as we do not have any property/method listed.



The below code I have used it for checkboxes in "SysListView32" and it works as expected.


 But for 'ListBox' the variable ‘nPos’ in Object_ShiftRight() method is not populated with the correct value it depends on what “Win32API.SendMessage(oInteraction.guiObject.Handle, LVM_GETITEMSTATE, nItemID, LVIS_STATEIMAGEMASK)”sends and it is ‘0’.


 


LVM_GETITEMSTATE = 4140

LVIS_STATEIMAGEMASK = &HF000

nShiftVal = Object_ShiftRight(Win32API.SendMessage(guiObject.Handle, LVM_GETITEMSTATE, nItemID, LVIS_STATEIMAGEMASK), 12)


 


Public Function Object_ShiftRight(nPos, nShift)


Dim nPostShift


    nPostShift = nPos \ (2 ^ nShift)


    If (nPos mod (2 ^ nShift) <> 0) And (nPos < 0) Then


      nPostShift = nPostShift - 1


    End If


    Object_ShiftRight = nPostShift


End Function


 I am not sure why the Win32API method is sending the wrong value.

Please let me know how to fix this issue. 



Thanks,

Suvidh Shetty



6 Replies


  • Hi Suvidh,



    I am guessing that you are working with a Visual C++ application. If this is the case then the control you are working with is, most probably, CCheckListBox. If my assumption is correct, you can make use of the native methods and properties of the control in order to get information on check boxes. That is, to determine whether a check box in the CCheckBoxList control is checked or not, you need to use the native method. If you need to check an item, you need to use the SetCheck method. Here is a sample script demonstrating how to use the methods. It checks the first item in a check list box if it is unchecked and unchecks if it is checked:

    Sub ChangeState

      Dim ListBox, Checked

      Set ListBox = Sys.Process("<MY_APP>").Window(<MY_WINDOW>).Window(<MY_CHECKLISTBOX>)

      Checked = ListBox.GetCheck(0)

      If Checked = 0 Then

        Call ListBox.SetCheck(0, 1)

      Else

        Call ListBox.SetCheck(0, 0) 

      End If

    End Sub


    Please note that the native members in C++ application are available for TestComplete only if the tool has access to the debug information for the application. Please ask the developers to provide you with the debug information for the application to make this solution to work. Please find more information in the Open Applications in Visual C++ help topic.
  • suvidhshetty_1's avatar
    suvidhshetty_1
    Occasional Contributor

    Hi,



    Following is the update that I have tried.



    What is the Control?

     ‘CXTCheckListBox’. 


    What exactly happens when I tried the suggestion?  

    I tried the below script but ‘GetCheck(0)’ and SetCheck () is not a native method of TestComplete.

    The error message I get is ‘Unable to find ‘GetCheck(0)’ method.’ 


    Sub Test2

      Dim <App> 

      Dim listBox


      Set chart = Aliases.<App> 

      Set listBox = chart.dlgPreferencesProcedureFiltersDefault.page32770.page32770.ListBox

      Checked = listBox.GetCheck(0)

      If Then

        Call listBox.SetCheck(0, 1)

      Else

        Call listBox.SetCheck(0, 0) 

      End If

    End Sub



    I have run the script in development environment with the Debug information with the following setting in TC:



    1. "Micosoft VC++ open application support" is checked in Install extension.

    2. The "Read debug information for statically linked libraries" is set.



    Please let me know proper steps on the things that i have to ensure before running this script.



    Do you want me to share the '.pdb' file.



    Thanks


  • Hi Suvidh,



    Thanks for information. CXTPCheckListBox is a control produced by Codejock. However, as I can see in the controls documentation, this control has the same native methods that allow working with checkboxes: GetCheck and SetCheck.



    Do you want me to share the '.pdb' file.
    I do not need this file. However, could you please confirm that this file is located in the same folder where the executable file of your application resides?



    Also, please select the list box object in the Object Browser panel, switch to the Methods tab at the right side of the panel and check whether there are the Debug Agent methods group in addition to the Standard, Actions and MFC groups. If this group is absent then TestComplete was unable to read debug information for the application.
  • Hi Suvidh,



    Here is another solution that does not require debug information for the tested application.



    To find out whether a specific item is checked, you need to save images of the checked and/or unchecked boxes to the Stores | Regions collection and compare an item's actual image with the saved image. Here is the script routine that saves an image of the checked box to the checkBox_Checked item of the Stores | Regions collection. Correct the values of the checkedBoxCaption and listBox variables in this routine to make them valid for your application. The checkedBoxCaption variable must contain the caption of a checked item.



    Sub SaveCheckBoxCheckedImage


      checkedBoxCaption = "Menu Bar"


      Set listBox = Sys.Process("CheckListBox").Window("#32770", "Codejock Check List Box Sample").Window("ListBox")




      Set bounds = listBox.wItemBounds(checkedBoxCaption) 


      Set checkedBoxImg = listBox.Picture(bounds.Left, bounds.Top, bounds.Height, bounds.Height)


      Call Regions.AddPicture(checkedBoxImg, "checkBox_Checked")


    End Sub




    Once the image is saved, you do not need to run this routine anymore. You can use the below isListBoxItemChecked routine in order to find out whether a specific item is checked.



    Function isListBoxItemChecked(listBox, itemCaption)


      Set bounds = listBox.wItemBounds(itemCaption)


      Set checkBoxImg = listBox.Picture(bounds.Left, bounds.Top, bounds.Height, bounds.Height)


      isListBoxItemChecked = Regions.Compare("checkBox_Checked", checkBoxImg, True, False, False, 0, lmNone)


    End Function




    To check a corresponding item of a list box, you need to simulate a click to the check box area of the needed item. The following CheckItem routine demonstrates this:



    Sub CheckItem(listBox, itemCaption, check)


      If Not (check = isListBoxItemChecked(listBox, itemCaption)) Then


        Set bounds = listBox.wItemBounds(itemCaption)


        Call listBox.ClickItemXY(itemCaption, bounds.Height / 2, bounds.Height / 2)


      End If   


    End Sub




    Here is a sample script demonstrating how to use this approach. The script works with the CheckListBox sample application available on the Codejock web site.



    Sub Test1


      Set listBox = Sys.Process("CheckListBox").Window("#32770", "Codejock Check List Box Sample").Window("ListBox")




      ' Check "Standard"


      Call CheckItem(listBox, "Standard", True)




      ' Uncheck "Advanced"


      Call CheckItem(listBox, "Advanced", False)


    End Sub
  • ThunduBeedi's avatar
    ThunduBeedi
    Occasional Contributor
    Hi David,



    I can't find the collection Regions in Stores. How do I add this?



    Thanks,

    Beedi

  • Hi Beedi,



    Right-click the Stores node, select the 'Add | New Item...' menu item and select the 'Regions' item in the 'Create Project Item' dialog.