Adrian123

virtual ListView sqlite

7 posts in this topic

#1 ·  Posted (edited)

Hi I need help with the code bellow, my goal is to make faster sqlite queries to Sqlite because _SQLite_GetTable2d seams to be slow on big tables.

Thank you :

 

https://www.autoitscript.com/forum/topic/182469-using-controls-to-edit-cells-in-a-listview/

 

Well my code is faster but a I have 2 issues :

1 Memory leaks

2 Listview ( virtual) a little slow when scrolling (column headers delay )

Please help I am not a WinApi specialist. (The hugetable its actuality much bigger I'm limited by upload size)

Thank You.

 

#comments-start

C++ Source of Dll

#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include "sqlite3.h"
using namespace std;



extern "C"
{
    // A function adding two integers and returning the result
    char * SqliteSelect(char *  path ,char  * sSql , char * rowsep, char * tabsep  )
    {
        std::string rez="";
        bool  once=true;
        sqlite3 *db;

        if ( sqlite3_open_v2(path, &db,SQLITE_OPEN_READONLY, NULL) == SQLITE_OK)
    {
        sqlite3_stmt *stmt;
        if (sqlite3_prepare_v2(db, sSql, -1, &stmt, 0) == SQLITE_OK)
            {
            int nCols = sqlite3_column_count(stmt);
            while (sqlite3_step(stmt) == SQLITE_ROW)
            {
            for (int nCol = 0; nCol < nCols; nCol++)
                    {
                    if (once==true)
                                {
                                    rez+=(char *) sqlite3_column_name(stmt, nCol);
                                     if (nCol < nCols-1 )
                                     {
                                        rez+=tabsep;
                                     }

                                                     else {
                                         rez+=rowsep;
                                            once=false;
                                           // sqlite3_reset(stmt);
                                            nCol=0;
                                                     }
                                }

                            if (once==false){

                                        if ( sqlite3_column_text(stmt, nCol)!=nullptr)
                                        {
                                            rez+=(char *) sqlite3_column_text(stmt, nCol);
                                        }
                                        if (nCol < nCols-1 )
                                             rez+=tabsep;
                                    }
                        }
                    rez+=rowsep;
            }

        }
        else {

return (char *)sqlite3_errmsg(db);

        sqlite3_close(db);


    }


        sqlite3_close(db);
    }


 char *cstr = new char[rez.length() + 1];
    strcpy(cstr, rez.c_str());
    return cstr;
    }



char * SqliteExec(char *  path ,char  * sSql  )
    {
std::string rez="Error: ";
            sqlite3 *db;
           char *error;
        if ( sqlite3_open_v2(path, &db,SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK)
            {

        sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL,&error);
               if( sqlite3_exec(db, sSql, NULL, NULL, &error) != SQLITE_OK )
               {
                rez+= (char *)sqlite3_errmsg(db);
                  sqlite3_exec(db, "ROLLBACK", NULL, NULL, &error);
                sqlite3_close(db);
               }
              sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &error);
             sqlite3_close(db);
if (rez=="Error: " )
{
  rez="OK";
}
char *cstr = new char[rez.length() + 1];
    strcpy(cstr, rez.c_str());
    return cstr;

            }

    }

}




#comments-end


#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIvkeysConstants.au3>
#include <WinAPIShellEx.au3>


#include <GuiEdit.au3>

Opt( "MustDeclareVars", 1 )


Global $hListView, $iItem = -1, $iSubItem = 0, $aRect
Global  $idComboOpen, $idComboClose, $bComboOpen = False, $bComboDoNotOpen = False
Global $bEditEscape = True, $bEditUpDown = False, $bListboxOpen = False
Global $bComboOpenOnEnter = True
Global $bComboOpenOnSpace = False
Global $bComboOpenOnDoubleClick = True
Global $bListboxAcceptClickEnter = True
Global $hEdit
;Global $Table



Func __SQLite_StringToUtf8Struct($sString)
    Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _
            "ptr", 0, "int", 0, "ptr", 0, "ptr", 0)
    If @error Then Return SetError(1, @error, "") ; DllCall error
    Local $tText = DllStructCreate("char[" & $aResult[0] & "]")
    $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $sString, "int", -1, _
            "struct*", $tText, "int", $aResult[0], "ptr", 0, "ptr", 0)
    If @error Then Return SetError(2, @error, "") ; DllCall error
    Return $tText
EndFunc   ;==>__SQLite_StringToUtf8Struct

    Global $Headers ,$RowsArray
Global $TabSep =@TAB
Example()

Func Compare_Headers($ArrayIni,$Array_)

    If   UBound($ArrayIni)<> UBound($Array_) Then
    Return 1
    EndIf

    For $R=0 to UBound($ArrayIni)-1
        if $ArrayIni[$R] <> $Array_[$R] Then
        Return 1
        EndIf
    Next

Return 0
EndFunc

#include <File.au3>
Func nCheckDB( $sDBname , $SSQL , $idListView )

    Local $iniH =$Headers;

    GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT,0, 0)

    Local $RowSep =@LF
    Local $tFilename = __SQLite_StringToUtf8Struct($sDBname)
    Local $tSsql = __SQLite_StringToUtf8Struct($SSQL )

    Local $hDLL = DllOpen("libSlqiteFaster.dll")
    Local $Arrx = DllCall($hDLL,"STR" ,"SqliteSelect",  "struct*", $tFilename ,"struct*" ,$tSsql ,"struct*" ,__SQLite_StringToUtf8Struct($RowSep) ,"struct*" ,__SQLite_StringToUtf8Struct($TabSep) )

    DllClose($hDLL)

     $RowsArray= StringSplit($Arrx[0],$RowSep)
     $Headers=StringSplit($RowsArray[1],$TabSep)
      Local $iCols = $Headers[0]
    Local $iRows = $RowsArray[0]

    If Compare_Headers( $iniH,$Headers)=1 Then

        While _GUICtrlListView_GetColumnCount($idListView)>0
            _GUICtrlListView_DeleteColumn ( $idListView, 0 )
        WEnd


                For $i = 1 To $iCols
                            _GUICtrlListView_AddColumn( $idListView,$Headers[ $i ], 75 )
                        Next

    EndIf

    GUICtrlSendMsg( $idListView, $LVM_SETITEMCOUNT, $iRows-2, 0 )

;$RowsArray=0
;$Headers=0
$iRows=0
$iCols=0
$tFilename=0
$tSsql=0

EndFunc




Func Example()

Local $hGui = GUICreate( "LV_", @DesktopWidth-20, @DesktopHeight-40,-1,-1, $WS_SIZEBOX+$WS_MAXIMIZEBOX+ $WS_MINIMIZEBOX )

Global $Button3 = GUICtrlCreateButton("Ne3", 400, 0, 75, 25)
Global $Button1 = GUICtrlCreateButton("NeSmler", 100, 0, 75, 25)

    Local $idListView
    Local $pListViewCallback
    Local $pEditCallback
    Local $pListCommand
    Local $pGuiCallback


    ;MsgBox(0,"","STOP")
    $idListView= GUICtrlCreateListView( "", 10, 40, @DesktopWidth-20-20, @DesktopHeight-80-100,$LVS_OWNERDATA ) ;$LVS_NOCOLUMNHEADER
    _GUICtrlListView_SetExtendedListViewStyle( $idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT,$LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES) ) ; $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT +
    GUICtrlSetResizing($hGui, $GUI_DOCKBORDERS)
    $hListView = GUICtrlGetHandle( $idListView )
    ; Subclass ListView to handle messages related to ComboBox


    ; ComboBox open and close events
    $idComboOpen = GUICtrlCreateDummy()
    $idComboClose = GUICtrlCreateDummy()

    GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

    ; Subclass callback functions
    $pListViewCallback= DllCallbackGetPtr( DllCallbackRegister( "ListViewCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
    $pEditCallback = DllCallbackGetPtr( DllCallbackRegister( "EditCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
     $pListCommand = DllCallbackGetPtr( DllCallbackRegister( "ListCommand", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
     $pGuiCallback = DllCallbackGetPtr( DllCallbackRegister( "GuiCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hListView, $pListViewCallback, 9998, 0 )

    ; Show GUI
    GUISetState( @SW_SHOW )
    ; Message loop
    While 1
        Switch GUIGetMsg()

            Case $Button3
                GuiSetState(@SW_LOCK, $hGui)
            nCheckDB("bigtable.sqlite" ,"SELECT * FROM hugetable;",$idListView )
            GuiSetState(@SW_UNLOCK, $hGui)
            Case $Button1
                GuiSetState(@SW_LOCK, $hGui)
    For $i = 0 To _GUICtrlListView_GetColumnCount($idListView)-1
                            _GUICtrlListView_SetColumnWidth ( $hListView, $i,  $LVSCW_AUTOSIZE_USEHEADER  ) ;$LVSCW_AUTOSIZE
                        Next

GuiSetState(@SW_UNLOCK, $hGui)

#cs
    Local $S_PH = "C:\\Users\\achis\\Desktop\\PP2C 24.11.2015_OK\\Prod.sqlite"
    Local $SSQLi ="UPDATE sumbomLVL_Static Set part='10000611' WHERE rowid=1 ;"
    Local $hDLL = DllOpen("libSlqiteFaster.dll")
    Local $Arrx = DllCall($hDLL,"STR" ,"SqliteExec",  "struct*",  __SQLite_StringToUtf8Struct($S_PH) ,"struct*" ,__SQLite_StringToUtf8Struct($SSQLi)  )
    MsgBox ( 0,"",$Arrx[0])

    DllClose($hDLL)


#ce


            Case $idComboOpen
                If $bComboOpen Then
                    ; If another ComboBox is open then delete it
                    _WinAPI_RemoveWindowSubclass( $hEdit, $pEditCallback, 9999 )
                    ;_WinAPI_RemoveWindowSubclass( $hListView, $pListCommand, 9999 )
                    _WinAPI_RemoveWindowSubclass( $hGui, $pGuiCallback, 9999 )
                    _GUICtrlEdit_Destroy( $hEdit )
                EndIf

$hEdit = _GUICtrlEdit_Create( $hListView,_GUICtrlListView_GetItemText( $hListView, $iItem, $iSubItem ), $aRect[0], $aRect[1], $aRect[2] - $aRect[0],20,$ES_AUTOHSCROLL )
_GUICtrlEdit_SetSel( $hEdit, 0, -1 )
                ; Create subclasses to handle Windows messages
                _WinAPI_SetWindowSubclass( $hEdit, $pEditCallback, 9999, 0 )    ; Messages from the Edit control of the ComboBox
                ;_WinAPI_SetWindowSubclass( $hListView, $pListCommand, 9999, 0 ) ; WM_COMMAND messages from Listbox part of ComboBox
                _WinAPI_SetWindowSubclass( $hGui, $pGuiCallback, 9999, 0 )      ; Handle GUI messages related to ComboBox control
                ; Set focus to ComboBox                                         ; Subclasses are used only when ComboBox is open
                _WinAPI_SetFocus( $hEdit )
                $bComboOpen = True


            Case $idComboClose

                If Not $bComboOpen Then ContinueLoop
                If GUICtrlRead( $idComboClose ) Then
                    Local $c_item = StringSplit($RowsArray[$iItem+2],$TabSep)[$iSubItem+1]

                Local $T = StringSplit(  $RowsArray[$iItem+2],$TabSep)


                $T[$iSubItem] =_GUICtrlEdit_GetText( $hEdit )
                $RowsArray[$iItem+2]=_ArrayToString($T,$TabSep)


                    _WinAPI_SetFocus( $hListView ) ; Set focus to ListView
                EndIf
                ; Delete ComboBox control
                _WinAPI_RemoveWindowSubclass( $hEdit, $pEditCallback, 9999 )
                ;_WinAPI_RemoveWindowSubclass( $hListView, $pListCommand, 9999 )
                _WinAPI_RemoveWindowSubclass( $hGui, $pGuiCallback, 9999 )
                _GUICtrlEdit_Destroy( $hEdit )
                $bComboOpen = False


            Case $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_SECONDARYDOWN
                If Not $bComboOpen Then ContinueLoop
                ; Clicks in Listbox part of ComboBox should not delete it
                If $bListboxOpen Then ContinueLoop
                ; Clicks in Edit part of ComboBox should not delete it
                Local $aPos = MouseGetWindowPos( $hListView )
                If Not ( $aPos[0] > $aRect[0] And $aPos[0] < $aRect[2] And $aPos[1] > $aRect[1] And $aPos[1] < $aRect[1] + 20 ) Then
                    GUICtrlSendToDummy( $idComboClose ) ; Delete ComboBox
                    Local $aSize = WinGetPos( $hListView )
                    If $aPos[0] > 0 And $aPos[1] > 0 And $aPos[0] < $aSize[2] And $aPos[1] < $aSize[3] Then _
                        _WinAPI_SetFocus( $hListView ) ; Set focus to ListView if mouse click is inside ListView
                EndIf

            Case $GUI_EVENT_CLOSE
                  Exit

                If Not $bEditEscape Then ExitLoop
                $bEditEscape = False
        EndSwitch
    WEnd

    ; Cleanup
    GUIDelete()
EndFunc



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

    Local Static $bNotXP = Not ( @OSVersion = "WIN_XP" )
    Local Static $tRect = DllStructCreate( $tagRECT )
    Local Static $hBrush = _WinAPI_CreateSolidBrush( 0xFFFF00 )
    Local Static $tText = DllStructCreate( "wchar[50]" )
    Local Static $pText = DllStructGetPtr( $tText )

    Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
    Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
    Local $iCode = DllStructGetData( $tNMHDR, "Code" )

    Switch $hWndFrom
        Case $hListView
            Switch $iCode


            Case $LVN_GETDISPINFOW
                    Local $tNMLVDISPINFO = DllStructCreate( $tagNMLVDISPINFO, $lParam )

                ;   $LV_DISPINFO *lpdi = ($LV_DISPINFO *)$lParam;

                    If BitAND( DllStructGetData( $tNMLVDISPINFO, "Mask" ), $LVIF_TEXT ) Then
                        Local $iIndex = DllStructGetData( $tNMLVDISPINFO, "Item" )
                        Local $Subindex = DllStructGetData($tNMLVDISPINFO,"SubItem")
                            Local $sItem =  StringSplit($RowsArray[$iIndex+2],$TabSep)[$Subindex+1] ;  $aResult[$iIndex][DllStructGetData($tNMLVDISPINFO,"SubItem")]
                            DllStructSetData( $tText, 1, $sItem )
                            DllStructSetData( $tNMLVDISPINFO, "Text", $pText )
                            DllStructSetData( $tNMLVDISPINFO, "TextMax", StringLen( $sItem ) )

                    EndIf


                Case $NM_CUSTOMDRAW

                    Local $tNMLVCustomDraw = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
                    Local $dwDrawStage = DllStructGetData( $tNMLVCustomDraw, "dwDrawStage" )
                    Switch $dwDrawStage                                ; Specifies the drawing stage
                        ; Stage 1
                        Case $CDDS_PREPAINT                              ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW                    ; Stage 2 will be carried out

                        ; Stage 2
                        Case $CDDS_ITEMPREPAINT                          ; Before an item is painted
                            If Not _GUICtrlListView_GetItemState( $hListView, DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ), $LVIS_FOCUSED ) Then Return $CDRF_NEWFONT ; Default drawing of item
                            $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" )
                            Return $CDRF_NOTIFYSUBITEMDRAW                 ; Stage 3 will be carried out

                        ; Stage 3
                        Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM )  ; Before a subitem is painted

                            Return $CDRF_NOTIFYPOSTPAINT                   ; Stage 4 will be carried out


                        ; Stage 4
                        Case BitOR( $CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM ) ; After a subitem has been painted

                            If DllStructGetData( $tNMLVCustomDraw, "iSubItem" ) = $iSubItem Then
                                Local $hDC = DllStructGetData( $tNMLVCUSTOMDRAW, "hdc" )                   ; Device context
                                $aRect = _GUICtrlListView_GetSubItemRect( $hListView, $iItem, $iSubItem )  ; Subitem rectangle
                                $aRect[2] = $aRect[0] + _GUICtrlListView_GetColumnWidth( $hListView, $iSubItem )

                                DllStructSetData( $tRect, "Left",   $aRect[0]+4 )
                                DllStructSetData( $tRect, "Top",    $aRect[1] )
                                DllStructSetData( $tRect, "Right",  $aRect[2] )
                                DllStructSetData( $tRect, "Bottom", $aRect[3] )
                                _WinAPI_FillRect( $hDC, $tRect, $hBrush )                                  ; Fill subitem background
                                _WinAPI_SetTextColor( $hDC, 0x000000 )                                     ; Set black text color

                                DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + 2 ) ; Adjust rectangle
                                If $bNotXP Then DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 2 )

                                _WinAPI_DrawText( $hDC, StringSplit($RowsArray[$iItem+2],$TabSep)[$iSubItem+1], $tRect, $DT_WORD_ELLIPSIS ) ; Draw text
                            EndIf
                            Return $CDRF_NEWFONT                           ; $CDRF_NEWFONT must be returned after changing font or colors
                    EndSwitch
                Case $NM_CLICK
                    If Not $bComboDoNotOpen And Not $bComboOpenOnDoubleClick And $iItem > -1 And $iSubItem > -1 Then _
                        GUICtrlSendToDummy( $idComboOpen ) ; Send message to open ComboBox
                Case $NM_DBLCLK
                    If $bComboOpenOnDoubleClick And $iItem > -1 And $iSubItem > -1 Then _
                        GUICtrlSendToDummy( $idComboOpen ) ; Send message to open ComboBox
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

; Handle ListView messages related to ComboBox
Func ListViewCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
    Switch $iMsg



        ; Open ComboBox on Enter key
        Case $WM_GETDLGCODE
            Switch $wParam
                Case $VK_RETURN
                    If Not $bComboDoNotOpen And $bComboOpenOnEnter And $iItem > -1 And $iSubItem > -1 Then
                        _GUICtrlListView_SetItemSelected( $hListView, -1, False )
                        _GUICtrlListView_SetItemSelected( $hListView, $iItem )
                        GUICtrlSendToDummy( $idComboOpen )
                    EndIf
            EndSwitch

        ; Manage multiple selections
        ; Prevent ComboBox from opening
        ; Manage keyboard events
        Case $WM_KEYDOWN
            Switch $wParam
                Case $VK_SHIFT, $VK_CONTROL
                    $bComboDoNotOpen = True
                ; Manage keyboard events
                Case $VK_LEFT
                    If Not $bComboDoNotOpen And $iSubItem > 0 Then $iSubItem -= 1
                    _GUICtrlListView_RedrawItems( $hListView, $iItem, $iItem )
                Case $VK_RIGHT
                    If Not $bComboDoNotOpen And $iSubItem < _GUICtrlListView_GetColumnCount( $hListView ) - 1 Then $iSubItem += 1
                    _GUICtrlListView_RedrawItems( $hListView, $iItem, $iItem )
                Case $VK_SPACE
                    If Not $bComboDoNotOpen And $bComboOpenOnSpace And $iItem > -1 And $iSubItem > -1 Then
                        _GUICtrlListView_SetItemSelected( $hListView, -1, False )
                        GUICtrlSendToDummy( $idComboOpen )
                    EndIf
            EndSwitch
        Case $WM_KEYUP
            Switch $wParam
                Case $VK_SHIFT, $VK_CONTROL
                    $bComboDoNotOpen = False
            EndSwitch

        ; Left click in ListView
        ; Sent on single and double click
        ; Determines item/subitem of the cell that's clicked
        Case $WM_LBUTTONDOWN
            Local $aHit = _GUICtrlListView_SubItemHitTest( $hListView )
            If $bComboOpen Then
                ; If another ComboBox is open then delete it
                _GUICtrlEDIT_Destroy( $hEdit )
                GUICtrlSendToDummy( $idComboClose )
                _WinAPI_SetFocus( $hListView )
            EndIf
            If $aHit[0] > -1 And $aHit[1] > -1 Then
                $iItem = $aHit[0]
                $iSubItem = $aHit[1]
                _GUICtrlListView_RedrawItems( $hListView, $iItem, $iItem )
            EndIf

        ; Delete ComboBox on right click in ListView and on left
        ; or right click in non-client ListView area (Scrollbars).
        Case $WM_RBUTTONDOWN, $WM_NCLBUTTONDOWN, $WM_NCRBUTTONDOWN
            _GUICtrlEDIT_Destroy( $hEdit )
            GUICtrlSendToDummy( $idComboClose )
            _WinAPI_SetFocus( $hListView )
    EndSwitch

    ; Call next function in subclass chain
    Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
    #forceref $iSubclassId, $pData
EndFunc

; Messages from the Edit control of the ComboBox
Func EditCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
    Switch $iMsg
        ; Dialog codes
        Case $WM_GETDLGCODE
            Switch $wParam
                Case $VK_TAB    ; Close

                    GUICtrlSendToDummy( $idComboClose, True )
                Case $VK_RETURN  ; Accept and close
                    GUICtrlSendToDummy( $idComboClose, True )
                Case $VK_ESCAPE ; Close
                GUICtrlSendToDummy( $idComboClose, True )

                    _WinAPI_SetFocus( $hListView )
                    $bEditEscape = True

            EndSwitch

        ; Double click in Edit part of ComboBox
        Case $WM_LBUTTONDBLCLK
            Local $aPos = MouseGetWindowPos( $hListView )
            If $aPos[0] > $aRect[0] And $aPos[0] < $aRect[2] And $aPos[1] > $aRect[1] And $aPos[1] < $aRect[1] + 20 Then _
                GUICtrlSendToDummy( $idComboClose, True ) ; Accept and close
    EndSwitch

    ; Call next function in subclass chain
    Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
    #forceref $iSubclassId, $pData
EndFunc


; Handle GUI messages related to ComboBox control
Func GuiCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
    Switch $iMsg
        ; Delete ComboBox on left or right mouse click in non-client GUI area and on GUI deactivate
        Case $WM_NCLBUTTONDOWN, $WM_NCRBUTTONDOWN, $WM_ACTIVATE
        _GUICtrlEDIT_Destroy( $hEdit )
            GUICtrlSendToDummy( $idComboClose )
    EndSwitch

    ; Call next function in subclass chain
    Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
    #forceref $iSubclassId, $pData
EndFunc

; Get mouse pos relative to window
Func MouseGetWindowPos( $hWindow )
    Local $aPos = MouseGetPos()
    Local $tPoint = DllStructCreate( "int X;int Y" )
    DllStructSetData( $tPoint, "X", $aPos[0] )
    DllStructSetData( $tPoint, "Y", $aPos[1] )
    _WinAPI_ScreenToClient( $hWindow, $tPoint )
    $aPos[0] = DllStructGetData( $tPoint, "X" )
    $aPos[1] = DllStructGetData( $tPoint, "Y" )
    Return $aPos
EndFunc

 

 

 

 

OnefolderWorking.zip

Edited by Adrian123
Forgot

Share this post


Link to post
Share on other sites



#2 ·  Posted

When I run your script I get an empty listview. And .schema returns an error:

sqlite> .schema
Error: file is encrypted or is not a database

For a large database you should use the example in "Data stored in databases" in the thread about virtual listviews.

Share this post


Link to post
Share on other sites

#3 ·  Posted

20 hours ago, LarsJ said:

When I run your script I get an empty listview. And .schema returns an error:

sqlite> .schema
Error: file is encrypted or is not a database

For a large database you should use the example in "Data stored in databases" in the thread about virtual listviews.

Sorry I put everything in one zip should work now

OnefolderWorking.zip

Share this post


Link to post
Share on other sites

#4 ·  Posted

I only have pretty little time to dig into this but here are what strikes me.

  • You shouldn't open / close the DB at every SQL statement. Open it at program start and close it at program termination.
  • Test and handle SQLite error codes, not only SQLITE_OK.
  • Use a large SQLite cache. It won't make a diference first time but subsequent requests will run much faster.
  • You don't have to convert AutoIt (UTF16-LE) strings back and forth to/from UTF8. Use UTF16 SQLite primitives instead.
  • I understand the sample DB is only a toy but its schema lives me with questions about replicated columns.
  • You select * which is very bad. If ever your DB design changes for some good reasons someday, changing the order of columns, you'll have to change many things in the code. Select named columns and only those which are useful for the task at hand.
  • Your app design seems to load the whole DB in a huge listview, say with 180K rows, and let the user painfully navigate in this ocean. It's way more efficient and user-friendly to let the user select the criterions he needs for what he wants to view/change and, from that, build a query to select and load, in a manageable listview, only what he actually needs.
  • Create indices for speeding up the various specific queries mentionned above.
  • I have only little insight about the actual goals, but if you're dealing with automotive parts, you might find it useful and efficient to create columns (and indices) for manufacturer (car brand), item familly and create separate tables with foreign keys from there to ease queries. Generic items (light bulbs, tyres, accessories, ...) can populate a "Generic" brand.
1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank You

My goal is to make the fastest way to use sqlite and listview because I have an application in 

C++ combined with various exes built with Autoit,freePascal,exel VBA etc ,and I was thinking to gather everything in one application built with Autoit and some minimal dlls (data in DB is only for testing to see which method is the best, I will never have more than 1000 rows/30 colums but I need to make sure I don't have memory leaking since user don't close the application 😊 bad users)

I would like Autoit since the 'IDE' is small and portable and I also use Sap scripting from Autoit.(quite powerful)

I will take in consideration your advice.

 

Edited by Adrian123

Share this post


Link to post
Share on other sites

#6 ·  Posted

There are no memory leaks in the code in OnefolderWorking.zip. When you start scrolling a virtual listview it'll allocate working storage. It'll continue allocating memory until a sufficient large number of new listview cells has been displayed on the screen. In this example it can probably allocate up to around 1 MB of additional memory. If you don't scroll much you can see this memory allocation for a long time. When it has sufficient working storage it'll stop allocating more memory. This is completely normal behaviour of a virtual listview.

The delay in scrolling is caused by the fact that it's a virtual listview. The listview is updated through code in Windows DLL-files. This is very very fast code. Because it's a virtual listview the code is constantly sending messages ($LVN_GETDISPINFOW notifications contained in WM_NOTIFY messages) to your AutoIt code to get data for the next listview cell. The AutoIt code is slow compared to code in DLL-files. This makes the entire update process slow.

When you scroll horizontally the repositioning of the header is done after the listview cells has been updated. If 45 rows are visible on the screen 45 * 30 cells has to be updated (note that non-visible columns on left or right side are updated too). This takes time. And this is the reason for the delay in the header update.

When you are using a virtual listview you are executing much more AutoIt code for updating the listview than in a normal listview. This costs on performance. You should only use a virtual listview if you need to. That means if you have more than 100.000 cells. Or if you have other special reasons.

If you need only 1000 rows and 30 columns = 30,000 cells you should definitely use a normal listvew. Then the scrolling will be much smoother because the update is done entirely through the very fast code in the DLL-files. See "Using standard listviews" in the example about Virtual ListViews for code to fill out a normal listview in a fast way.

Share this post


Link to post
Share on other sites

#7 ·  Posted

Thank You for your feedback, 

I will make a code with  normal listview to see its behavior.

I guess there is not a good reason fro extreme speed in my case.   

 

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

  • Similar Content

    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit  
    • r0ash
      By r0ash
      Hey guys, MattDiesel over Stackoverflow mentioned this beautiful piece of code 
      #include <WindowsConstants.au3> #include <WinAPI.au3> Local $IDM_FONT = 33 Local $hWindow = WinGetHandle("Untitled - Notepad") _WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0) Local $hFontWin = WinWait("Font") $select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "") WinClose($hFontWin) MsgBox(0,"", $select) I realized that _WinAPI_PostMessage can trigger menu click event, even if Notepad is minimized.
      How do we know what is the decimal value of *any menu item or sub-menu item*? How we know "Format > Font" menu-item is 33 as wParam to _WinAPI_PostMessage()? Have a look at snapshot.
      Regards.

    • nacerbaaziz
      By nacerbaaziz
      Hello guys
      Today I'll give you three functions to manage the list View items
      These functions will help you to do some works in your list view items
      1. list view Read
      To get the selected item text  
      2. listView_checke
      To checke an item
      3. isListViewChecked
      To see if the item is checked
      All of these functions will be illustrated by the following example
      You can download the include file from the link below
      Now with the example
      #include <easy_listView_functions.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example()  Local $idListview  GUICreate("ListView Get Item Checked State", 1000, 700)  $idListview = GUICtrlCreateListView("", 50, 30, 250, 120, 50)  _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) ; Add items $item1 = GUICtrlCreateListViewItem("item1", $idListview) $item2 = GUICtrlCreateListViewItem("item2", $idListview) _listview_Checke($idListview, "item1") $btn = GUICtrlCreateButton("&read", 100, 150, 50, 50) $btn2 = GUICtrlCreateButton("&if checked", 100, 200, 100, 50)  GUISetState(@SW_SHOW) while 1 switch GUIGetMSG() case $GUI_EVENT_CLOSE  GUIDelete() exit case $btn $read = _ListView_read($idListView) if $read then msgBox(0, "read listview", $read) else msgBox(0, "read listview", "no text ditected") endIf case $btn2 if _isListviewChecked($idListView, "item1") then msgBox(0, "get", "the item is checked") else msgBox(0, "get", "the item isn't checked") endIf endSwitch wend EndFunc   ;==>Example
       
      easy_listView_functions.au3
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys
      I am working on a little project, in which I have to retrieve 8000+ rows of data from a table, from a SQLite database, to populate a combobox 
      This is what I tried 'til now, but it still takes about 12 seconds to populate the combobox.
      _SQLite_Exec($objDatabase, "BEGIN TRANSACTION;") If _SQLite_GetTable($objDatabase, "SELECT DISTINCT Comune FROM LISTA_COMUNI;", $arrRisultatoQuery, $intRighe, $intColonne) = $SQLITE_OK Then For $i = 2 To UBound($arrRisultatoQuery) - 1 If $i < UBound($arrRisultatoQuery) - 1 Then GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i] & "|") Else GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i]) EndIf Next _SQLite_Exec($objDatabase, "COMMIT;") Are there any other solution to retrieve 8000+ records from a SQLite database?
      Thank you very much  
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt