QTP/UFT support tip: How to use windows messaging system to get the state of a winlistview item
There are syslistview32 controls that show checkboxes on each item. One easy sample to found is in the system configuration application.
1.Click on "Start>Run"
4.Select services tab
- Declare the constants
Const LVM_GETITEMSTATE = &H102C
Const LVIS_STATEIMAGEMASK = &HF000
This are constants used as parameters for the sendmessage function. For more information visit this site:
2. Then declare the library which has the sendmessage function.
Extern.Declare micLResult, "SendMessage", "User32.dll","SendMessage", micHwnd, micLong, micUInteger, micString
Additional information can be found in this article: Document ID KM177243 - How to run a function from a DLL (QTP)
3. Get the index of the item you want to check (in this sample using an input box).
lvIndex = clng(inputbox("Index?", , 5))
4. Obtain the handle of the SysListView32 control
hwnd = clng(Dialog("System Configuration").WinListView("SysListView32").GetROProperty("hwnd"))
5. Activate the main parent control of the application to ensure it will be on top and focused (in this sample the main parent is the Dialog control)
6. Use the windows SendMessage command
res = Extern.SendMessage(hwnd, LVM_GETITEMSTATE, lvIndex, LVIS_STATEIMAGEMASK)
The parameters will return the item state, 8192 for checked or 4096 for uncheked
For additional information visit this site: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
7. Validate the response and display the response
If res = 4096 Then
print "Row Is Unchecked"
ElseIf res = 8192 Then
print "Row Is Checked"
Note: Remember that this is a sample for troublesooting purpose in order to check if the control respond, you need to type right handle the control and index of the item.
The Opinions expressed in my post are mine alone, and do not reflect the opinions of my employer. No warranties express or implied for any answered posted.