Jump to content
Sign in to follow this  
0Ethan0

How to achieve a responsive GUI while running a function with a loop?

Recommended Posts

0Ethan0

Ahoy Autoit Community!

After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution :)

The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).

The Setup: GUI with a ListView Control and a simple exit button.

The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.

The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.

The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.

The Code (stripped and simplified as much as I could):

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

Opt("GUIOnEventMode", 1)

HotKeySet("{Esc}", "_Exit")

Global $c=0
Global $ssGDI[3], $ssGraphic[2], $ssImage
Global Const $bg_color = "000000"
Global Const $ssW = 480, $ssH = 320
Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH )


$guiW = 1200
$guiH = 726
$mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP)
$Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50)
GUICtrlSetOnEvent($Button1, "_Exit")
$Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50)
GUICtrlSetOnEvent($Button1, "Test")


Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280)
_GUICtrlListView_SetColumnWidth ($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth ($ListView, 1, 100)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("Name 1|Category 1", $ListView)
GUICtrlCreateListViewItem("Name 2|Category 2", $ListView)

screenshotWidgetInit($ssW,$ssH, 690, 100)
GUISetState(@SW_SHOW, $mainWindow)

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _Exit()
    EndSwitch
WEnd

Func Test()
    For $k = 1 To UBound($aFiles) - 1
        screenshotWidgetTransition($aFiles[$k])
    Next
EndFunc

Func ListView_Click()
    ConsoleWrite("Left Click")
EndFunc

Func ListView_DoubleClick()
    ConsoleWrite("Double Left Click")
    Test()
EndFunc

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
    Case $wParam = $ListView
        Select
            Case $event = $NM_CLICK
                ListView_Click ()
            Case $event = $NM_DBLCLK
                ListView_DoubleClick ()
            EndSelect
    EndSelect
    Return $GUI_RUNDEFMSG
EndFunc

Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000)
    Local $a, $d = $c, $iX, $iY
    $ssImage = _GDIPlus_ImageLoadFromFile($image)
    $iX = _GDIPlus_ImageGetWidth($ssImage)
    $iY = _GDIPlus_ImageGetHeight($ssImage)

    $FDesktop=$ssH/$ssW
    $Fact =1
    If $iX > $ssW And $FDesktop > ($iY/$iX) Then
        $Fact=$ssW/$iX
    ElseIf $iY > $ssH Then
        $Fact=$ssH/$iY
    EndIf
    $H1 = Round(($Fact * $iY),0)
    $W1 = Round(($Fact * $iX),0)

    _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1)

    WinSetTrans($ssGDI[$d], "", 0)
    WinSetOnTop($ssGDI[$d], "", 1)
    For $a = 0 To 254 Step $speed
        WinSetTrans($ssGDI[$d], "", $a)
        Sleep($delay)
    Next
    WinSetTrans($ssGDI[$d], "", 254)
    WinSetOnTop($ssGDI[Not ($d)], "", 0)
    WinSetTrans($ssGDI[Not ($d)], "", 0)
    _GDIPlus_GraphicsClear($ssGraphic[Not ($d)])
    $c = 1 - $d

    _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics
    Sleep($sleep)
EndFunc   ;==>screenshotWidgetTransition

Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY)
    $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow)
    $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2])
    $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2])
;    GUISetBkColor("0x" & $bg_color, $ssGDI[2])
    GUISetState(@SW_SHOW, $ssGDI[2])
    GUISetState(@SW_SHOW, $ssGDI[0])
    GUISetState(@SW_SHOW, $ssGDI[1])
    WinSetTrans($ssGDI[0], "", 0)
    WinSetTrans($ssGDI[1], "", 0)
    _GDIPlus_Startup()
    $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0])
    $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1])
    _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color)
    _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color)
EndFunc   ;==>screenshotWidgetInit

Func _Exit()
    _GDIPlus_ImageDispose($ssImage)
    _GDIPlus_GraphicsDispose($ssGraphic[0])
    _GDIPlus_GraphicsDispose($ssGraphic[1])
    GUIDelete($ssGDI[0])
    GUIDelete($ssGDI[1])
    GUIDelete($ssGDI[2])
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

I hope someone can shed light on this; perhaps a different approach is needed?

Thank you in advance!

P.S.
The script is patched from different scripts of different users in the forum - thank you again users! :)

Edited by 0Ethan0

Share this post


Link to post
Share on other sites
nend

You have some blocking function in it like sleep.
Also Guioneventmode give some problem in your case.

I fixed it, see the code.

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

HotKeySet("{Esc}", "_Exit")

Global $c=0
Global $ssGDI[3], $ssGraphic[2], $ssImage
Global Const $bg_color = "000000"
Global Const $ssW = 480, $ssH = 320
Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH )


$guiW = 1200
$guiH = 726
$mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP)
$Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50)
$Button2 = GUICtrlCreateButton("Test", 60, 0, 50, 50)


Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280)
_GUICtrlListView_SetColumnWidth ($ListView, 0, 100)
_GUICtrlListView_SetColumnWidth ($ListView, 1, 100)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("Name 1|Category 1", $ListView)
GUICtrlCreateListViewItem("Name 2|Category 2", $ListView)

screenshotWidgetInit($ssW,$ssH, 690, 100)
GUISetState(@SW_SHOW, $mainWindow)

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1
   _Check_MSG()
WEnd

Func _Check_MSG()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _Exit()
        Case $Button1
            _Exit()
        Case $Button2
            Test()
    EndSwitch
EndFunc

Func Test()
    For $k = 1 To UBound($aFiles) - 1
        screenshotWidgetTransition($aFiles[$k])
    Next
EndFunc

Func ListView_Click()
    ConsoleWrite("Left Click")
EndFunc

Func ListView_DoubleClick()
    ConsoleWrite("Double Left Click")
    Test()
EndFunc

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
    Case $wParam = $ListView
        Select
            Case $event = $NM_CLICK
                ListView_Click ()
            Case $event = $NM_DBLCLK
                ListView_DoubleClick ()
            EndSelect
    EndSelect
    Return $GUI_RUNDEFMSG
EndFunc

Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000)
    Local $a, $d = $c, $iX, $iY
    $ssImage = _GDIPlus_ImageLoadFromFile($image)
    $iX = _GDIPlus_ImageGetWidth($ssImage)
    $iY = _GDIPlus_ImageGetHeight($ssImage)

    $FDesktop=$ssH/$ssW
    $Fact =1
    If $iX > $ssW And $FDesktop > ($iY/$iX) Then
        $Fact=$ssW/$iX
    ElseIf $iY > $ssH Then
        $Fact=$ssH/$iY
    EndIf
    $H1 = Round(($Fact * $iY),0)
    $W1 = Round(($Fact * $iX),0)

    _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1)

    WinSetTrans($ssGDI[$d], "", 0)
    WinSetOnTop($ssGDI[$d], "", 1)
    For $a = 0 To 254 Step $speed
        WinSetTrans($ssGDI[$d], "", $a)
        _Check_MSG()
        Sleep($delay)
    Next
    WinSetTrans($ssGDI[$d], "", 254)
    WinSetOnTop($ssGDI[Not ($d)], "", 0)
    WinSetTrans($ssGDI[Not ($d)], "", 0)
    _GDIPlus_GraphicsClear($ssGraphic[Not ($d)])
    $c = 1 - $d

    _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics
    $timer = TimerInit()
    While TimerDiff($timer) < $sleep
        _Check_MSG()
    WEnd

EndFunc   ;==>screenshotWidgetTransition

Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY)
    $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow)
    $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2])
    $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2])
;    GUISetBkColor("0x" & $bg_color, $ssGDI[2])
    GUISetState(@SW_SHOW, $ssGDI[2])
    GUISetState(@SW_SHOW, $ssGDI[0])
    GUISetState(@SW_SHOW, $ssGDI[1])
    WinSetTrans($ssGDI[0], "", 0)
    WinSetTrans($ssGDI[1], "", 0)
    _GDIPlus_Startup()
    $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0])
    $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1])
    _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color)
    _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color)
EndFunc   ;==>screenshotWidgetInit

Func _Exit()
    _GDIPlus_ImageDispose($ssImage)
    _GDIPlus_GraphicsDispose($ssGraphic[0])
    _GDIPlus_GraphicsDispose($ssGraphic[1])
    GUIDelete($ssGDI[0])
    GUIDelete($ssGDI[1])
    GUIDelete($ssGDI[2])
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

 

Edited by nend
  • Thanks 1

Share this post


Link to post
Share on other sites
0Ethan0

nend, Thank you so much for the reply and the code - it gave me a clearer concept of how things work behind the Autoit scene : )

I also read in the Wiki about the exact problem I was facing --> https://www.autoitscript.com/wiki/Interrupting_a_running_function

I hope it's OK to share the link here, just for others who stumble upon this topic can have a better understanding.

 

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  

  • Similar Content

    • Broihon
      By Broihon
      Hey guys,

      I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.
      That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WinAPI.au3> $h_GUI = GUICreate("Test", 200, 200, 350, 350) $h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2) $h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam") $g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc)) GUISetState(@SW_SHOW) Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam) Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>WndProc_GUI Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DllCallbackFree($h_LV_NewWndProc) As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • Bllee
      By Bllee
      every time i press "delete button" delete a line, but i can't add new line with info. the id line write normally but i can't change or add new info
      obs: looking at the "includes" one realizes that already tried of everything that knew
      my code
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <StringConstants.au3> #include <Array.au3> #include <GuiListBox.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 612, 480, 192, 154) $MenuItem1 = GUICtrlCreateMenu("&Arquivo") $MenuItem2 = GUICtrlCreateMenuItem("Salvar Ctrl+S", $MenuItem1, $SS_CENTER) $MenuItem4 = GUICtrlCreateMenuItem("Carregar Ctrl+O", $MenuItem1, $SS_CENTER) $MenuItem3 = GUICtrlCreateMenuItem("Salvar Como Shitft+Ctrl+S", $MenuItem1, $SS_CENTER) $Group1 = GUICtrlCreateGroup("", 21, 8, 569, 97, $SS_CENTER) $Input1 = GUICtrlCreateInput("ID COR", 122, 32, 97, 21, $SS_CENTER) $Input2 = GUICtrlCreateInput("REGIÃO", 138, 64, 249, 21, $SS_CENTER) $Input3 = GUICtrlCreateInput("Label", 264, 30, 121, 21, $SS_CENTER) $Label1 = GUICtrlCreateLabel("Label", 232, 32, 30, 17, $SS_CENTER) $Button1 = GUICtrlCreateButton("Capturar Cor", 42, 30, 75, 25, $SS_CENTER) $Button2 = GUICtrlCreateButton("Capturar Região", 42, 62, 91, 25, $SS_CENTER) $Button3 = GUICtrlCreateButton("ADD", 442, 24, 113, 33) $Button5 = GUICtrlCreateButton("Delet", 442, 64, 113, 33) $Group2 = GUICtrlCreateGroup("Editar ID selecionado", 8, 384, 601, 57, $SS_CENTER) $Input7 = GUICtrlCreateInput("ID", 10, 402, 40,21, $SS_CENTER) $Input4 = GUICtrlCreateInput("COR", 51, 402, 121, 21, $SS_CENTER) $Input5 = GUICtrlCreateInput("REGIÃO", 173, 402, 249, 21, $SS_CENTER) $Input6 = GUICtrlCreateInput("LABEL", 423, 402, 121, 21, $SS_CENTER) $Button4 = GUICtrlCreateButton("\/", 544, 400, 30, 25, $SS_CENTER) $Button6 = GUICtrlCreateButton("/\", 574, 400, 30, 25, $SS_CENTER) ; Add column Global $id = Int(0) $List1 = GUICtrlCreateListView("",5, 120, 601, 253, $SS_CENTER) _GUICtrlListView_AddColumn($List1, "ID",40) _GUICtrlListView_AddColumn($List1, "COR",100) _GUICtrlListView_AddColumn($List1, "COORDENADA",305) _GUICtrlListView_AddColumn($List1, "LABEL",150) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MenuItem2 MsgBox($MB_SYSTEMMODAL, "ctrl + s", "Nothing Here",1) Case $MenuItem3 MsgBox($MB_SYSTEMMODAL, "shift+ctrl s", "Nothing Here",1) Case $MenuItem4 MsgBox($MB_SYSTEMMODAL, "ctrl + o", "Nothing Here",1) Case $Button1 MsgBox($MB_SYSTEMMODAL, "Capturar cor", "Aperte espaço para capturar a cor") GUICtrlSetData($Input1,MouseColor()) Case $Button2 MsgBox($MB_SYSTEMMODAL, "capturar região", "Aperte espaço para capturar a posição inicial") local $mouse = MouseGetPos() $x_init = $mouse[0] $y_init = $mouse[1] MsgBox($MB_SYSTEMMODAL, "capturar região", "Aperte espaço para capturar a posição final") local $mouse = MouseGetPos() $x_end = $mouse[0] $y_end = $mouse[1] GUICtrlSetData($Input2,$x_init&','&$y_init&' ; '&$x_end&','&$y_end) Case $Button3 _GUICtrlListView_AddItem($List1, $id, 1) ; id _GUICtrlListView_AddSubItem($List1, $id, GUICtrlRead($Input1), 1, 1) ;cor _GUICtrlListView_AddSubItem($List1, $id, GUICtrlRead($Input2), 2, 1) ;coordenada _GUICtrlListView_AddSubItem($List1, $id, GUICtrlRead($Input3), 3, 1) ;label $id= $id + 1 Case $Button4 $Item = _GUICtrlListView_GetSelectedIndices($List1) $Sid = _GUICtrlListView_GetItem($List1, Number($Item),0) $Scor = _GUICtrlListView_GetItem($List1, Number($Item),1) $Scord = _GUICtrlListView_GetItem($List1, Number($Item),2) $Slabel = _GUICtrlListView_GetItem($List1, Number($Item),3) ; get info GUICtrlSetData($Input7,$Sid[3]) GUICtrlSetData($Input4,$Scor[3]) GUICtrlSetData($Input5,$Scord[3]) GUICtrlSetData($Input6,$Slabel[3]) Case $Button5 _GUICtrlListView_DeleteItemsSelected($List1) Case $Button6 ; give back inf if GUICtrlRead($Input7) <> "ID" Then _GUICtrlListView_SetItem($List1, GUICtrlRead($Input4), GUICtrlRead($Input7),1) ;cor _GUICtrlListView_SetItem($List1, GUICtrlRead($Input5), GUICtrlRead($Input7),2) ;coordenada _GUICtrlListView_SetItem($List1, GUICtrlRead($Input6), GUICtrlRead($Input7),3) ;coordenada EndIf EndSwitch WEnd Func MouseColor() local $mouse = MouseGetPos() Return Hex(PixelGetColor($mouse[0],$mouse[1]), 6) EndFunc  
    • c.haslam
      By c.haslam
      I have
      Local $idListview = GUICtrlCreateListView("",8,8,@DesktopWidth/2-16,@DesktopHeight-150,$LVS_SHOWSELALWAYS, _ $LVS_EX_INFOTIP) Local $hListView = GUICtrlGetHandle($idListview) _GUICtrlListView_InsertColumn($hListview, 0, "Filename", 400) _GUICtrlListView_InsertColumn($hListview, 1, "Ext", 50) _GUICtrlListView_InsertColumn($hListview, 2, "Size",70) _GUICtrlListView_InsertColumn($hListview, 3, 'Date time',100) _GUICtrlListView_InsertColumn($hListview, 4, "Path", 385) _GUICtrlListView_InsertColumn($hListview, 5, "sizeInt", 0) _GUICtrlListView_JustifyColumn($hListview, $kSize,1) ; right align then further on
      While True $sFnamExt = FileFindNextFile($iSrch) If @error Then ExitLoop EndIf $sAtts = FileGetAttrib($sPath&'\'&$sFnamExt) If StringInStr($sAtts,'D') Then If $sFnamExt<>'$RECYCLE.BIN' Then $sDirs &= '?'&$sPath&'\'&$sFnamExt EndIf Else $p = StringInStr($sFnamExt,'.',0,-1) ; last If $p=0 Then $sFnam = $sFnamExt $sExt = '' Else $sFnam = StringLeft($sFnamExt,$p-1) $sExt = StringTrimLeft($sFnamExt,$p) EndIf _GUICtrlListView_AddItem($hListview,$sFnam,-1,_GUICtrlListView_GetItemCount($hListview)+1000) _GUICtrlListView_AddSubItem($hListview,$nItem,$sExt,$kExt) $nSize = FileGetSize($sPath&'\'&$sFnamExt) $sSize = AddThousandsSeparator($nsize) _GUICtrlListView_AddSubItem($hListview,$nItem,$sSize,$kSize) _GUICtrlListView_AddSubItem($hListview,$nItem,$nsize,$kSizeInt) $nTotBytes += $nSize $a1 = FileGetTime($sPath&'\'&$sFnamExt,$FT_MODIFIED,$FT_ARRAY) $t = $a1[0]&'-'&$a1[1]&'-'&$a1[2]&' '&$a1[3]&':'&$a1[4] _GUICtrlListView_AddSubItem($hListview,$nItem,$t,$kDateTime) _GUICtrlListView_AddSubItem($hListview,$nItem,$sPath,$kPath) If $gSQL Then $s = "Insert into tbl values ("&_SQLite_Escape($sFnam)&","&_SQLite_Escape($sExt)&",'"& _ $sSize&"','"& _ $t&"',"&_SQLite_Escape($sPath)&","&$nSize&")" _SQLite_Exec(-1,$s) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf EndIf EndIf WEnd FileClose($iSrch) You will see that I heeded the advice in Help > _GUICtrlListView_AddItem: "As AutoIt uses the $iParam parameter to store the controlID of native-created ListView items, this value should be set sufficiently high for UDF-created items to avoid possible conflict with any existing controls - a starting value of 1000 is recommended."
      (It's unfortunate that the Example does not heed this advice. OK, it doesn't need to because there are no other controls, but still --- it would help neophytes if it did. Also to me _GUICtrlListView_AddItem is not native because it is a UDF. Confused?)
      My script then does a sort using SQLite, and updates the ListView:
      Local $hQuery Local $colNames = ['fnam','ext','nsize','dateTime','path','SizeInt'] Local $s = "Select * FROM tbl ORDER BY "&$colNames[$ncol]&';' _SQLite_Query(-1,$s, $hQuery) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf Local $aRow[$kSizeInt+1] Local $iItem=-1 While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf $iItem += 1 For $i = $kFnam To $kSizeInt _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default) Next WEnd This works, but I had earlier coded
      _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default,$iItem+1000) because the same advice is in the Help for this function.
      So my care in specifying $param back-fired! What am I not understanding?
      The only difference in what works is that the $param parameter is defaulted.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
×