Jump to content

touchscreen and listview


Champak
 Share

Go to solution Solved by Champak,

Recommended Posts

I'm working with a touchscreen (not a multipoint screen) and I need to be able to do a couple things with the listview that I don't know how to accomplish.

1/ I need to be able to select multiple things by pressing the items without pressing the control button, then obviously unselect the items if I press one of the highlighted items again. Is this possible?

2/ I need to be able to drag an item or group of items to another point in the list. I can do that with a mouse with slight difficulty because the mouse icon has to be placed just right, but I can't seem to do that with my finger, the screen wont scroll up or down beyond what is already displayed (I'm assuming this one cant be fixed and is inherent in working with a touchscreen...just hoping).

Link to comment
Share on other sites

Hi,

For the first thing here you go :

#include <GUIConstants.au3>
#include <GUIListView.au3>

$hGUI = GUICreate("MyGUI")

$iLw1 = GUICtrlCreateListView("Col1|Col2", 10, 10, 380, 380, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))

For $i = 1 To 10
    GUICtrlCreateListViewItem($i & "|" & Chr($i + 80), $iLw1)
Next

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

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $iLw1
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")

                    _GUICtrlListView_SetItemChecked($hWndFrom, $iIndex, Not _GUICtrlListView_GetItemChecked($hWndFrom, $iIndex))
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Br, FireFox.

Link to comment
Share on other sites

Thanks. I don't understand your example. Are you trying to show me to use checkboxes as my point of reference in order to move multiple items...or do whatever I want with them...instead of keeping the list rows highlighted when I click on them? If you are, I already thought about doing that, but didn't want to go that route. I just want to keep my two column listview the way it is and keep whatever I click on highlighted until/if I click on it again...or close the window.

Link to comment
Share on other sites

Generally when you try to select multiple things, you have to hold down the ctrl button on the keyboard while you click on the item with the mouse. Using the touchscreen and no keyboard I can't do that. So I need to be able to select multiple items without clicking the ctrl.

Link to comment
Share on other sites

  • Moderators

Champak,

How do you select multiple items in other apps using this touchscreen - in Explorer for example? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

That's not what you were asking about in the original post, you asked if you could select multiple items using the touchscreen without holding the CTRL key. What you just said is not what you asked. You can use a touch screen just like a mouse in the same way as you do the mouse, press and hold on the screen and drag your finger over multiple items in the listview. I don't see how this relates to AutoIt in any way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I know what I just said had nothing to do with what I asked for. What I just said was replying to Melba's specific question. I know how a touchscreen works seeing how I use it everyday, and if what you said worked I wouldn't be here asking this question. This is autoit related because it happens in my app. Holding onto things and dragging my finger drags them to a different position in the list which you should have realized reading my op so closely (2).

Link to comment
Share on other sites

I suppose you could use a Windows message that you monitor to see if the listview has been clicked on. Although I have no idea how you'd differentiate between a single press selecting an item and another one clicking and dragging.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I think you are right when I think about it. So I think I'll do it that way with window messaging and then instead of using a dragging option, use an input and button function where I would input the index starting point I want everything moved to and press a button to execute, and when it's moved, the new position is brought into focus on the list view. Both problems solved. Now I just need some time to figure out how to do it. Thanks.

Link to comment
Share on other sites

This is what I have so far, not succeeding. My issues are commented.

#include <GUIConstants.au3>
#include <GUIListView.au3>

Global $TotalList[0]

$hGUI = GUICreate("MyGUI")

$iLw1 = GUICtrlCreateListView("Col1|Col2", 10, 10, 280, 200, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

For $i = 1 To 30
    GUICtrlCreateListViewItem($i & "|" & Chr($i + 80), $iLw1)
Next

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

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $iLw1
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")

                    $ListArray = _GUICtrlListView_GetSelectedIndices ($iLw1)

                    For $i = 0 To UBound($TotalList) - 1
                        If $TotalList[$i] = $ListArray Then
                            _ArrayDelete($TotalList, $i)
                            _GUICtrlListView_SetItemSelected ($iLw1, $ListArray, False);==This should unhighlight the item if I click on it a second time
                            Return
                        EndIf
                    Next

                    _ArrayAdd($TotalList, $ListArray)

                    For $j = 0 To UBound($TotalList) - 1
                        ConsoleWrite("+ " & $TotalList[$j] & @CRLF)
                    Next
                    ConsoleWrite("----------" & @CRLF)

                    If UBound($TotalList) >= 1 Then
                        For $j = 0 to UBound($TotalList) - 1
                            _GUICtrlListView_SetItemSelected($iLw1, $TotalList[$j]);==This should highlight all the items in the array
                        Next
                    EndIf
                    ;_ArrayDisplay($TotalList)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Also as a side note, I don't know if this is a bug or not, but I've always had this issue with autoit (or scite) but couldn't come up with a condense reproduction outside of my app because I didn't know what was actually causing it. If you uncomment that _arraydisplay at the end, it will cause the script to have a fit and exit. It only seems to happen at certain points within certain functions. This is only one example, I've seen it happen around other functions. Is this a known bug? This has happened on all the computers I've had, all versions of autoit I've had since 2009, fresh hard drive installs, Win xp and 7.

Link to comment
Share on other sites

You can't use a blocking function like _ArrayDisplay inside a window's message function like that, it usually hard locks the computer or crashes the script/computer.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You can do this :

AdlibRegister("MyFunc", 0)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func MyFunc()
    AdlibUnRegister("MyFunc")
    Local Static $fCall = False
    If $fCall Then Return 0
    $fCall = True
    _ArrayDisplay($TotalList) ;make $Totallist as global
    $fCall = False
EndFunc

The call flag is to avoid the function to be called multiple times before the arraydisplay is closed, so you will only have one arraydisplay at time.

Br, FireFox.

Link to comment
Share on other sites

BrewManNH, that maybe so, but that is just one example. I've had it happen in regular "self created" functions. I can't readily find one now, because when it happens I'm basically forced to move the arraydisplay somewhere else later in the function to prevent it from happening. If I come across one again, I'll try to condense the function and post it. But it's beyond that example of messaging functions.

FireFox, I'm not seeing your entire post, it looks like some of it is cut off.

Link to comment
Share on other sites

  • Solution

Figured it out. Apparently I needed the Number() function around the indices to be highlighted otherwise it returns false.

#include <GUIConstants.au3>
#include <GUIListView.au3>

Global $TotalList[0]

$hGUI = GUICreate("MyGUI")

$iLw1 = GUICtrlCreateListView("Col1|Col2", 10, 10, 280, 200, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))

For $i = 1 To 30
    GUICtrlCreateListViewItem($i & "|" & Chr($i + 80), $iLw1)
Next

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

While GUIGetMsg() <> $GUI_EVENT_CLOSE
    Sleep(10)
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $LV_Add = True
    Local $LV_Exit = False

    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    Local $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iIDFrom
        Case $iLw1
            Switch $iCode
                Case $NM_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")


                    $ListArray = _GUICtrlListView_GetSelectedIndices ($iLw1)


                    For $i = UBound($TotalList) - 1 To 0 Step - 1
                        If $TotalList[$i] = $ListArray Then
                            ConsoleWrite("--" & $i & "--" & $TotalList[$i] & @CRLF)

                            If UBound($TotalList) = 1 Then
                                $LV_Exit = True
                                Sleep(1000);==The last item wont unhilight unless this is here
                            EndIf

                            _ArrayDelete($TotalList, $i)
                            _GUICtrlListView_SetItemSelected ($iLw1, Number($ListArray), False)
                            $LV_Add = False
                            If $LV_Exit = True Then
                                $LV_Exit = False
                                Return
                            EndIf
                        EndIf
                    Next


                    If $LV_Add = True Then _ArrayAdd($TotalList, $ListArray)


                    ConsoleWrite("----------" & @CRLF)


                    If UBound($TotalList) >= 1 Then
                        For $j = 0 to UBound($TotalList) - 1
                            $444 = _GUICtrlListView_SetItemSelected($iLw1, Number($TotalList[$j]))
                            ConsoleWrite(">>> " & $j & "___" & $TotalList[$j] & "___" & $444 & @CRLF)
                        Next
                    EndIf
                    ;_ArrayDisplay($TotalList)
                  ;  AdlibRegister("MyFunc", 0)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc
Edited by Champak
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...