Jump to content

checkboxes in a syslistview32 contorol


Recommended Posts

Hi!

This is my first post on the board. I discovered this powerful script language only yesterday, and i've quick realized that it's a great piece of software to accomplish a lot of tasks :(

However, let's get to the point. The first thing i'm trying to do is to enable or disable some network components in the "Local Area Connection Properties".

Here there's a SysListView32 object containing the components list with a checkbox for each component (Client for Microsoft Networks, File and Printer Sharing for Microsoft Networks, etc.) . I would like to get the status of the checkboxes to know if i have to change it or not. It would also be ok to send a specific command to check or uncheck them, while sending a spacebar keypress doesn't work because it only switches their status, and again i'd have to know it in advance.

I've found how to do it with "standalone" checkboxes, but since these are inside a SysListView32 object, i don't know how, or even if it's possible, to refer directly to them.

Thanks in advance for any help.

ByE!

Edited by bReAkDoWN

[font="Arial"]-- without contraries there is no progression...[/font]

Link to comment
Share on other sites

Hi!

This is my first post on the board. I discovered this powerful script language only yesterday, and i've quick realized that it's a great piece of software to accomplish a lot of tasks   :(

However, let's get to the point. The first thing i'm trying to do is to enable or disable some network components in the "Local Area Connection Properties".

Here there's a SysListView32 object containing the components list with a checkbox for each component (Client for Microsoft Networks, File and Printer Sharing for Microsoft Networks, etc.) . I would like to get the status of the checkboxes to know if i have to change it or not. It would also be ok to send a specific command to check or uncheck them, while sending a spacebar keypress doesn't work because it only switches their status, and again i'd have to know it in advance.

I've found how to do it with "standalone" checkboxes, but since these are inside a SysListView32 object, i don't know how, or even if it's possible, to refer directly to them.

Thanks in advance for any help.

ByE!

<{POST_SNAPBACK}>

You can try to search "SysListView32" in the forum. I think this was discussed :( Edited by jpm
Link to comment
Share on other sites

I have been searching a lot in the forum before posting, but i couldn't find a solution for my problem. I can assure you..  :(

Bye!

<{POST_SNAPBACK}>

You don't need to ensure. I just want to point out one post in case of it help you.

The reference to search was just you it exist in this forum. very helpfull.

It is true in this specific case, only those which have been with the forum can remeber and even in this case it is not obvious.

Does the post help you ?

Welcome in the AutoIt World. :(

Link to comment
Share on other sites

You don't need to ensure. I just want to point out one post in case of it help you.

The reference to search was just you it exist in this forum. very helpfull.

It is true in this specific case, only those which have been with the forum can remeber and even in this case it is not obvious.

Yes, i agree with you.. Unfortunately in this case i haven't found any useful information to solve my problem..

Maybe, at the current development stage of autoit, isn't possible to do what i'm trying to (checking the state of, or exactly controlling check boxes in a listview32), but i can't be sure of it, so i'd like someone to put some light on this or give me some suggestions..

Welcome in the AutoIt World. :(

<{POST_SNAPBACK}>

Thank you! :(

Bye!

[font="Arial"]-- without contraries there is no progression...[/font]

Link to comment
Share on other sites

I just added a UDF called _GUICtrlListViewGetCheckedState and sent it to jdeB, so hopefully next beta it will be there, should be able to use it for what your wanting to do, you'll just have to get the handle to the control, and pass that and a zero-based index of the item you want the check state from.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I just added a UDF called _GUICtrlListViewGetCheckedState and sent it to jdeB, so hopefully next beta it will be there, should be able to use it for what your wanting to do, you'll just have to get the handle to the control, and pass that and a zero-based index of the item you want the check state from.

<{POST_SNAPBACK}>

I'm looking forward to trying it out, then i'll let you know my results.. :(

byE!

[font="Arial"]-- without contraries there is no progression...[/font]

Link to comment
Share on other sites

I have been searching a lot in the forum before posting, but i couldn't find a solution for my problem. I can assure you..  :(

Bye!

<{POST_SNAPBACK}>

Try reading up on ListView_GetCheckState @ MSDN

I messed around with a DLLCall that should work for checking the radiobutton in a listview, but I couldn't get it to work properly.

Maybe JPM or one of the other guys can take a look at it.

Here is the code and a screen grab of the window I was using for the test.

WinActivate ("Local Area Connection Properties")

WinWaitActive ("Local Area Connection Properties")

$Count = ControlListView("Local Area Connection Properties", "", "SysListView321", "GetItemCount")
$handle = ControlGetHandle("Local Area Connection Properties", "", "SysListView321")

For $x = 0 To $Count -1 Step 1
    ControlListView("Local Area Connection Properties", "", "SysListView321", "Select", $x)
    $result = DllCall("comctl32.dll", "int", "ListView_GetCheckState", "hwnd", $handle, "int", $x)
    If @error = 1 Then
        MsgBox(0, "Warning", "Test Failed")
    ElseIf $result[0] <> 0 Then 
        MsgBox(0, "Unchecked", ControlListView("Local Area Connection Properties", "", "SysListView321", "GetText", $x))
    EndIf
Next
Edited by Kerberuz

Kerby

Link to comment
Share on other sites

Try reading up on ListView_GetCheckState @ MSDN

I messed around with a DLLCall that should work for checking the radiobutton in a listview, but I couldn't get it to work properly.

Maybe JPM or one of the other guys can take a look at it.

Here is the code and a screen grab of the window I was using for the test.

Thank you very much for your help!

I will try too to mess around with this way of handling the problem, while waiting for some other guys' opinions and suggestions..

Thanks again..

byE!

[font="Arial"]-- without contraries there is no progression...[/font]

Link to comment
Share on other sites

To get it to work properly in AutoIt you'll need the latest beta version which incoporates DllStruct functions, because you'll need to creat a structure and a pointer to the structure.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Being the UDF didn't make it to the beta i'll make this simple for you.

#include <GuiConstants.au3>
#include <GuiListView.au3>

Global Const $LVIF_STATE = 0x8
Global Const $LVM_GETITEMA = ($LVM_FIRST + 5)


opt('MustDeclareVars', 1)
Dim $listview, $Btn_Get, $Btn_Exit, $msg, $Status, $ret
GUICreate("ListView Get Checked State", 392, 322)

$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_REGIONAL))
GUICtrlCreateListViewItem("index 0|data1|more1", $listview)
GUICtrlCreateListViewItem("index 1|data2|more2", $listview)
GUICtrlCreateListViewItem("index 2|data3|more3", $listview)
GUICtrlCreateListViewItem("index 3|data4|more4", $listview)
GUICtrlCreateListViewItem("index 4|data5|more5", $listview)
_GUICtrlListViewSetColumnWidth ($listview, 0, 100)
$Btn_Get = GUICtrlCreateButton("Get From Index 2", 150, 200, 90, 40)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)
$Status = GUICtrlCreateLabel("", 0, 302, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
         ExitLoop
      Case $msg = $Btn_Get
         GUICtrlSetData($Status, "")
         Local $is_Checked = _GUICtrlListViewGetCheckedState ($listview, 2)
         If ($is_Checked <> $LV_ERR) Then
            If ($is_Checked) Then
               GUICtrlSetData($Status, "Item is Checked")
            Else
               GUICtrlSetData($Status, "Item not Checked")
            EndIf
         EndIf
   EndSelect
WEnd
Exit

;===============================================================================
;
; Description:          _GUICtrlListViewGetCheckedState
; Parameter(s):     $h_listview - controlID
;                           $i_index - zero-based index to retrieve item check state from
; Requirement:          $LVS_EX_CHECKBOXES used in extended style when creating listview
; Return Value(s):  Returns 1 if checked
;                           Returns 0 if not checked
;                           If error then $LV_ERR is returned
; User CallTip:     _GUICtrlListViewGetCheckedState($h_listview, $i_index) Returns the check state for a list-view control item (required: <GuiListView.au3>)
; Author(s):            Gary Frost (custompcs@charter.net)
; Note(s):              :
;
;===============================================================================
Func _GUICtrlListViewGetCheckedState($h_listview, $i_index)
;~  typedef struct _LVITEM {
;~       UINT mask;
;~       int iItem;
;~       int iSubItem;
;~       UINT state;
;~       UINT stateMask;
;~       LPTSTR pszText; string buffer[255]
;~       int cchTextMax;
;~       int iImage;
;~       LPARAM lParam;
;~  #if (_WIN32_IE >= 0x0300)
;~       int iIndent;
;~  #endif
;~  #if (_WIN32_IE >= 0x560)
;~       int iGroupId;
;~       UINT cColumns; // tile view columns
;~       PUINT puColumns;
;~  #endif
;~  } LVITEM, *LPLVITEM;
   Local Const $Checked_State = 0x2000
   Local $isChecked = 0
   Local $struct = "uint;int;int;uint;uint"
   Local $p = DllStructCreate ($struct)
   DllStructSetData ($p, 1, $LVIF_STATE)
   DllStructSetData ($p, 2, $i_index)
   DllStructSetData ($p, 5, $LVIS_STATEIMAGEMASK)
   Local $ret = GUICtrlSendMsg($h_listview, $LVM_GETITEMA, 0, DllStructGetPtr ($p))
   If (Not $ret) Then
      DllStructDelete ($p)
      Return $LV_ERR
   EndIf
   
   If (BitAND(DllStructGetData ($p, 4), $Checked_State) == $Checked_State) Then
      $isChecked = 1
   EndIf
   DllStructDelete ($p)
   Return $isChecked
EndFunc  ;==>_GUICtrlListViewGetCheckedState

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hi!

I've got some news.. Thanks to Kerberuz' and Gafrost's suggestions, i've come to some interesting results, that maybe could be useful to Gafrost too..

I'll start from the beginning..

Since i had to read the state of checkboxes that weren't part of a listview created inside autoit, i didn't know the control_id needed by GUICtrlSendMsg, so i first tried to modify _GUICtrlListViewGetCheckedState, replacing the GuiCtrlSendMsg with

Local $ret =  DllCall("user32.dll","int","SendMessage", "hwnd",$h_listview, "int",$LVM_GETITEMA, "int",0, "int", DllStructGetPtr ($p))

with $h_listview obtained in the following way:

WinWaitActive ("ListView Get Checked State")
$handle = ControlGetHandle("ListView Get Checked State", "", "SysListView321")
....
....
Local $is_Checked = _GUICtrlListViewGetCheckedState ($handle, 2)

It worked flawlessy, so i tried to use it on my target: the Local Area Connection Properties window..

WinWaitActive ("Local Area Connection Properties")
$handle = ControlGetHandle("Local Area Connection Properties", "", "SysListView321")
....
....
Local $is_Checked = _GUICtrlListViewGetCheckedState ($handle, 2)

Explorer crashed.. The first thing i tried was to give some more bytes (a random amount to cover all fields of the structure) to the dllstruct, even if with the lvif_state we were using, they weren't needed, at least in theory.

Local $struct = "uint;int;int;uint;uint;int;int;int;int;int;int;int"
   Local $p = DllStructCreate ($struct)

At this point explorer was no longer crashing, but the status field of the dllstruct wasn't getting the state image number, but was always 0.

So, this method was working with the listview created with autoit gui, while it wasn't with the Local Area Properties one.

And here comes the suggestion given by Kerberuz..

Looking for some informations on the ListView_GetCheckState function, i discovered.. that it wasn't a function, but a macro that again called SendMessage, but this time with another message: LVM_GETITEMSTATE instead of LVM_GETITEM..

And the good news is that LVM_GETITEMSTATE doesn't require any structure to work, but it can be used to retrieve the state of a list-view item, passing the state information needed and the listview item index as lparam and wparam of the sendmessage() function!

This way:

Global Const $LVM_GETITEMSTATE = ($LVM_FIRST+ 44)
..............
..............
Local $ret =  DllCall("user32.dll","int","SendMessage", "hwnd",$h_listview, "int",$LVM_GETITEMSTATE, "int",2, "int", $LVIS_STATEIMAGEMASK)

This method works with both autoit gui and local area connection properties listviews. The Local Area listview, however, doesn't return 0x1000 and 0x2000 as state image numbers, but 0x3000 and 0x2000. Maybe that's because there's is a little icon near each checkbox.

This is what i've discovered so far, thanks to your suggestions.

Comments (even negative ones :( ) are always welcome!

[font="Arial"]-- without contraries there is no progression...[/font]

Link to comment
Share on other sites

Thanks for your input, this has been tricky.

Give this a try and let me know, this should work on both the system and gui listview, only tested with system listview with checkboxes and image, need to find one with checkboxes but no image for further testing.

;===============================================================================
;
; Description:            _GUICtrlListViewGetCheckedState
; Parameter(s):        $h_listview - controlID
;                            $i_index - zero-based index to retrieve item check state from
; Requirement:            $LVS_EX_CHECKBOXES used in extended style when creating listview
; Return Value(s):    Returns 1 if checked
;                            Returns 0 if not checked
;                            If error then $LV_ERR is returned
; User CallTip:        _GUICtrlListViewGetCheckedState($h_listview, $i_index) Returns the check state for a list-view control item (required: <GuiListView.au3>)
; Author(s):            Gary Frost (custompcs@charter.net)
; Note(s):                :
;
;===============================================================================
Func _GUICtrlListViewGetCheckedState($h_listview, $i_index)
   Local Const $Checked_State = 0x2000
   Local $isChecked = 0, $ret
   $ret = GUICtrlSendMsg($h_listview, $LVM_GETITEMSTATE, $i_index, $LVIS_STATEIMAGEMASK)
   If (Not $ret) Then
      $ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_listview, "int", $LVM_GETITEMSTATE, "int", $i_index, "int", $LVIS_STATEIMAGEMASK)
      If ($ret[0] == -1) Then
         Return $LV_ERR
      Else
         If (BitAND($ret[0], 0x3000) == 0x3000) Then
            $isChecked = 0
         Else
            $isChecked = 1
         EndIf
      EndIf
   Else
      If (BitAND($ret, 0x2000) == 0x2000) Then
         $isChecked = 1
      EndIf
   EndIf
   Return $isChecked
EndFunc  ;==>_GUICtrlListViewGetCheckedState
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thanks for your input, this has been tricky.

Give this a try and let me know, this should work on both the system and gui listview, only tested with system listview with checkboxes and image, need to find one with checkboxes but no image for further testing.

I'll give it a look as soon as possible.. I have enjoyed this sort of team work..

Bye!

Edited by bReAkDoWN

[font="Arial"]-- without contraries there is no progression...[/font]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...