Jump to content
myspacee

Scroll GUICtrlCreateList with mousewheel, and events

Recommended Posts

myspacee

Hello,

try to scroll up & down file list using mouse wheel :

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>

GUIRegisterMsg(0x020A, "_Mousewheel")

$sFolder = @ScriptDir & "\"



;GUI
GUICreate("Automation", 300, 500)

$refresh_todo = GUICtrlCreateButton("refresh", 10, 35, 75, 20)
$mylist = GUICtrlCreateList("", 10, 60, 280, 300)

_refresh_todo_list()

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $refresh_todo
            _refresh_todo_list()

        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
 WEnd




 func _refresh_todo_list()

    Local $FileList = _FileListToArray($sFolder, "*.*")

   If @error = 1 Then
       MsgBox(0, "", "No Folders Found.")
       Exit
   EndIf
   If @error = 4 Then
       MsgBox(0, "", "No Files Found.")
       Exit
    EndIf

   For $i = 1 To $FileList[0]
       GUICtrlSetData($mylist, $FileList[$i])
   Next
 EndFunc




Func _Mousewheel($hWnd, $msg, $l, $r)
    If $l = 0xFF880000 Then ; Mouse wheel up
        tooltip("Mousewheel up")
        Send("{UP}")
    Else ; Mouse wheel down
        tooltip("Mousewheel down")
        Send("{DOWN}")
    EndIf
    sleep (1000)
    tooltip("")
EndFunc   ;==>_Mousewheel

This code doesn't works, i can't understand why send is lost when focus is on a list element...

 

Everytime I select an element (with mouse or manually) :

- i must retrieve selection (namefile)

- allow to read file (are all .txt) when press mouse wheel button

- copy content to clipboard

 

Maybe, I can't undestand how intercept mouse correctly.

Can you help me ?

 

thank you,

m.

 

Share this post


Link to post
Share on other sites
Melba23

myspacee,

This seems a rather roundabout way of doing it, but it does work unless you rotate the scroll wheel really quickly:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
;#include <Array.au3>
#include <GuiListBox.au3>

$sFolder = @ScriptDir & "\"
$iList_Height = 300

; Create GUI
$hGUI = GUICreate("Automation", 300, 500)

$refresh_todo = GUICtrlCreateButton("refresh", 10, 35, 75, 20)
$mylist = GUICtrlCreateList("", 10, 60, 280, $iList_Height)

$hList = GUICtrlGetHandle($mylist)

$cDummy = GUICtrlCreateDummy() ; Create dummy control to act when scroll occurs

_refresh_todo_list()

GUISetState(@SW_SHOW)

; Set focus to button
ControlFocus($hGUI, "", $refresh_todo)

GUIRegisterMsg($WM_MOUSEWHEEL, "_Mousewheel")

; Determine how many items visible and thus offset of mid point
$iItem_Height = _GUICtrlListBox_GetItemHeight($mylist)
$iMid_Offset = Int($iList_Height / $iItem_Height / 2)

While 1
    Switch GUIGetMsg()
        Case $refresh_todo
            _refresh_todo_list()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $cDummy
            ; Dummy fired from within handler
            $iIndex = GUICtrlRead($cDummy)                          ; Read index of highlighted item
            $iTopIndex = $iIndex - $iMid_Offset                     ; Determine requried top item
            If $iTopIndex > -1 Then
                _GUICtrlListBox_SetTopIndex($mylist, $iTopIndex)    ; Set if not below 0
            EndIf
    EndSwitch

    ; Keep focus from listto prevent scrollbar eating the mousewheel message
    If _WinAPI_GetFocus() = $hList Then
        ControlFocus($hGUI, "", $refresh_todo)
    EndIf
WEnd

Func _refresh_todo_list()

    Local $FileList = _FileListToArray($sFolder, "*.*")

   If @error = 1 Then
       MsgBox(0, "", "No Folders Found.")
       Exit
   EndIf
   If @error = 4 Then
       MsgBox(0, "", "No Files Found.")
       Exit
    EndIf

   For $i = 1 To $FileList[0]
       GUICtrlSetData($mylist, $FileList[$i])
   Next

   GUICtrlSetState($refresh_todo, $GUI_FOCUS)

 EndFunc

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

    ; get index of highlighted item
    $iIndex = _GUICtrlListBox_GetCaretIndex($mylist)
    ; If ther is a highlighted item
    If $iIndex <> - 1 Then

        If $wParam = 0xFF880000 Then ; Mouse wheel up
            $iIndex -= 1
            If $iIndex = -1 Then $iIndex = 0
        Else ; Mouse wheel down
            $iIndex += 1
            If $iIndex = _GUICtrlListBox_GetCount($mylist) Then $iIndex -= 1
        EndIf
        ; Click on required item
        _GUICtrlListBox_ClickItem($mylist, $iIndex)
        ; Action dummy so scrolling takes place outside the handler
        GUICtrlSendToDummy($cDummy, $iIndex)
    EndIf
    ; Prevent scrollbar from reacting
    Return 0
EndFunc   ;==>_Mousewheel

Perhaps someone else can come up with a better way, but ListBoxes are pretty primitive controls and are not easy thing with which to interact.

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
myspacee

Hello,

thank you for reply and code, but hower I can't  use to reach my goal.

I hope is  possible 'reserve' mouse wheel up/down and redirect this user motion to GUICtrlCreateList.

 

Try to explain my needs :

- with another script i collect text from web/doc/pdf/etc and apply some 'rules' to text (i obtain a lot of txt files (>400), enriched wiht Adob3 Ind3sign styles)

- I want to allow my users to 'navigate' through these files using mouse wheel and follow specific order, without move focus from 'paste' application (files are ordered by first step)

 

At this point, as you suggest, ListBoxes not suite my needs. I think to use a list GUI to allow my users follow job and give them freedom to choose files to paste and go on.

 

Is possible to reserve mouse wheel and redirect this 'motion' to another GUI ?

I search an easy way to follow a list without obliging my users  to go back and forth.

 

Thank you for your time,

m.

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

×