Sign in to follow this  
Followers 0
JLogan3o13

[Solved] Grouping ListViews Without WM_Notify

6 posts in this topic

#1 ·  Posted (edited)

I have a GUI with several ListViews, and am trying to obtain the ItemText from just the "active" one. Looking to group the listviews so only one is active at a time. Below is a reproducer to show the basic GUI framework. Each of the listviews has multiple columns, which I use _GUICtrlListView_GetItemTextArray to get the text of. What I am after is basically similar to grouping radio buttons or checkboxes; when one listview is active the others are not.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

$hGUI_Main = GUICreate("Test", 500, 350)
GUISetState(@SW_SHOW)

$btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30)

$sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250)
_GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_AddColumn($sListView, "Resource ID")
    _GUICtrlListView_SetColumnWidth($sListView, 0, 100)
    _GUICtrlListView_SetColumnWidth($sListView, 1, 100)

$sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250)
_GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_AddColumn($sListView2, "Resource ID")
    _GUICtrlListView_SetColumnWidth($sListView2, 0, 100)
    _GUICtrlListView_SetColumnWidth($sListView2, 1, 100)


        _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI")
        _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1)
        _GUICtrlListView_AddItem($sListView, "Adobe Reader XI")
        _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1)
        _GUICtrlListView_AddItem($sListView, "Camtasia Studio")
        _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1)
        _GUICtrlListView_AddItem($sListView, "FA3")
        _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1)

        _GUICtrlListView_AddItem($sListView2, "Windows 7 x86")
        _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 7 x64")
        _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 8 x86")
        _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 8 x64")
        _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnGo
                $aTextListView = _GUICtrlListView_GetItemTextArray($sListView)
                $aTextListView2 = _GUICtrlListView_GetItemTextArray($sListView2)
                MsgBox(0, "", "Active Selections are: " & $aTextListView[1] & " and " & $aTextListView2[1])
        EndSwitch
    WEnd

GUIDelete()

In the past I have done this with WM_NOTIFY, when the user double clicks on a selection it can pull the text regardless of which listview it is in. But it has always been double-click driven, and single-column listviews, rather than the way I am attempting it here. I'm just curious if anyone has ever done anything similar, and if I am overlooking an obvious and simple way of doing this.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites



To close the loop on this, I never did come up with a better solution. I cobbled the below together, using radio buttons (grouped together if necessary), but that is just ugly. Putting it up on the shelf for the time being.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

$hGUI_Main = GUICreate("Test", 500, 350)
GUISetState(@SW_SHOW)

$btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30)

$sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250)
_GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_AddColumn($sListView, "Resource ID")
    _GUICtrlListView_SetColumnWidth($sListView, 0, 100)
    _GUICtrlListView_SetColumnWidth($sListView, 1, 100)

$sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250)
_GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_AddColumn($sListView2, "Resource ID")
    _GUICtrlListView_SetColumnWidth($sListView2, 0, 100)
    _GUICtrlListView_SetColumnWidth($sListView2, 1, 100)


        _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI")
        _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1)
        _GUICtrlListView_AddItem($sListView, "Adobe Reader XI")
        _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1)
        _GUICtrlListView_AddItem($sListView, "Camtasia Studio")
        _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1)
        _GUICtrlListView_AddItem($sListView, "FA3")
        _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1)

        _GUICtrlListView_AddItem($sListView2, "Windows 7 x86")
        _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 7 x64")
        _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 8 x86")
        _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 8 x64")
        _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1)

$rApps = GUICtrlCreateRadio("Applications", 10, 270, 100, 17)
$rOS = GUICtrlCreateRadio("OS", 250, 270, 100, 17)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnGo
                If GUICtrlRead($rApps) = 1 Then
                    $aTemp = _GUICtrlListView_GetItemTextArray($sListView)
                        MsgBox(0, "", $aTemp[1])
                ElseIf GUICtrlRead($rOS) = 1 Then
                    $aTemp = _GUICtrlListView_GetItemTextArray($sListView2)
                        MsgBox(0, "", $aTemp[1])
                Else
                    ;Do something else
                EndIf
        EndSwitch
    WEnd

GUIDelete()

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

JLogan3o13,

I missed this when you posted the first time. This is what I do in my GUIListViewEx UDF - look for a single click on a ListView and save the handle in a Global variable:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $hCurrListView, $aListView[2]

$hGUI_Main = GUICreate("Test", 500, 350)
GUISetState(@SW_SHOW)

$btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30)

$sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250)
$aListView[0] = $sListView
_GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_AddColumn($sListView, "Resource ID")
_GUICtrlListView_SetColumnWidth($sListView, 0, 100)
_GUICtrlListView_SetColumnWidth($sListView, 1, 100)

$sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250)
$aListView[1] = $sListView2
_GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_AddColumn($sListView2, "Resource ID")
_GUICtrlListView_SetColumnWidth($sListView2, 0, 100)
_GUICtrlListView_SetColumnWidth($sListView2, 1, 100)


_GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI")
_GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1)
_GUICtrlListView_AddItem($sListView, "Adobe Reader XI")
_GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1)
_GUICtrlListView_AddItem($sListView, "Camtasia Studio")
_GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1)
_GUICtrlListView_AddItem($sListView, "FA3")
_GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1)

_GUICtrlListView_AddItem($sListView2, "Windows 7 x86")
_GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1)
_GUICtrlListView_AddItem($sListView2, "Windows 7 x64")
_GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1)
_GUICtrlListView_AddItem($sListView2, "Windows 8 x86")
_GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1)
_GUICtrlListView_AddItem($sListView2, "Windows 8 x64")
_GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $btnGo
            $aTemp = _GUICtrlListView_GetItemTextArray($hCurrListView)
            MsgBox(0, "", $aTemp[1])
    EndSwitch
WEnd

GUIDelete()

Func _WM_NOTIFY($nWnd, $iMsg, $wParam, $lParam)
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = $NM_CLICK Then  ; Code
        $hCurrListView = DllStructGetData($tStruct, 1)                 ; ListView handle
    EndIf
EndFunc
Any use? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

 I in fact was just giving your UDF another look to see if I might use it for this scenario. :)

This works well for the reproducer I posted; I will spend some time this afternoon plugging this into the actual script to see if it works. As always, many thanks.

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You can use NM_SETFOCUS and NM_KILLFOCUS as shown below.

 

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $hFocus = 0

$hGUI_Main = GUICreate("Test", 500, 350)

$btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30)

$sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250)
_SetStyle($sListView, $WS_TABSTOP, 1)
_GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_AddColumn($sListView, "Resource ID")
    _GUICtrlListView_SetColumnWidth($sListView, 0, 100)
    _GUICtrlListView_SetColumnWidth($sListView, 1, 100)

$sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250)
_SetStyle($sListView2, $WS_TABSTOP, 1)
_GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
    _GUICtrlListView_AddColumn($sListView2, "Resource ID")
    _GUICtrlListView_SetColumnWidth($sListView2, 0, 100)
    _GUICtrlListView_SetColumnWidth($sListView2, 1, 100)


        _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI")
        _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1)
        _GUICtrlListView_AddItem($sListView, "Adobe Reader XI")
        _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1)
        _GUICtrlListView_AddItem($sListView, "Camtasia Studio")
        _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1)
        _GUICtrlListView_AddItem($sListView, "FA3")
        _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1)

        _GUICtrlListView_AddItem($sListView2, "Windows 7 x86")
        _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 7 x64")
        _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 8 x86")
        _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1)
        _GUICtrlListView_AddItem($sListView2, "Windows 8 x64")
        _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1)

;$rApps = GUICtrlCreateRadio("Applications", 10, 270, 100, 17)
;$rOS = GUICtrlCreateRadio("OS", 250, 270, 100, 17)

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnGo
                If $hFocus Then
                    $aTemp = _GUICtrlListView_GetItemTextArray($hFocus)
                    If ($aTemp[0] <> 0) And ($aTemp[1] <> "") Then
                        MsgBox(0, "", $aTemp[1], 0, $hGUI_Main)
                    EndIf
                EndIf
        EndSwitch
    WEnd

GUIDelete()

Func _SetStyle($hWnd, $iStyle, $fSet, $fExStyle = 0, $fUpdate = 0)

    Local $Flag, $Style

    If $fExStyle Then
        $Flag = -20
    Else
        $Flag = -16
    EndIf
    $Style = _WinAPI_GetWindowLong($hWnd, $Flag)
    If Not $fSet Then
        _WinAPI_SetWindowLong($hWnd, $Flag, BitAND($Style, BitNOT($iStyle)))
    Else
        _WinAPI_SetWindowLong($hWnd, $Flag, BitOR($Style, $iStyle))
    EndIf
    If $fUpdate Then
        _WinAPI_InvalidateRect($hWnd, 0, 0)
    EndIf
EndFunc   ;==>_SetStyle

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom')
    Local $ID = DllStructGetData($tNMIA, 'Code')

    Switch $hWnd
        Case $hGUI_Main
            Switch $hTarget
                Case $sListView, $sListView2
                    Switch $ID
                        Case $LVN_BEGINDRAG
                            Return 0
                        Case $NM_KILLFOCUS
                            $hFocus = $hTarget
                        Case $NM_SETFOCUS
                            _SetStyle($hTarget, $LVS_SHOWSELALWAYS, 1)
                            If ($hFocus) And ($hFocus <> $hTarget) Then
                                _SetStyle($hFocus, $LVS_SHOWSELALWAYS, 0, 0, 1)
                            EndIf
                            $hFocus = $hTarget
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by Yashied

Share this post


Link to post
Share on other sites

Thanks to both of you. I was able to make it work very well, even with a number of listviews.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
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
Sign in to follow this  
Followers 0