rootx

listview color selected item [SOLVED]

33 posts in this topic

#21 ·  Posted

Work perfect. THX

Now I have to study your script....

One question again, how can I remove the dots in the edge?

Share this post


Link to post
Share on other sites



#22 ·  Posted

rootx,

What dots in what edge?

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

#23 ·  Posted

4 minutes ago, Melba23 said:

rootx,

What dots in what edge?

M23

!! sorry, I meant the border around the selected item.

Cattura.PNG

Share this post


Link to post
Share on other sites

#24 ·  Posted

rootx,

My _NoFocusLines UDF will do the trick for button, sllder, radio and checkbox  controls, but I have never tried to do the same for a ListView. Not a trivial task in my opinion.

M23

1 person likes this

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

#25 ·  Posted

If you know how it's close to being trivial. This is the example for GUICtrlCreateListView in the help file:

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

Example()

Func Example()
  GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
  GUISetBkColor(0x00E0FFFF) ; will change background color

  Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
  Local $idButton = GUICtrlCreateButton("Remove dotted focus rectangle", 10, 170, 200, 20)
  Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
  Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
  Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
  GUICtrlCreateInput("", 20, 200, 150)
  GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
  GUISetState(@SW_SHOW)
  GUICtrlSetData($idItem2, "ITEM1")
  GUICtrlSetData($idItem3, "||COL33")
  GUICtrlDelete($idItem1)

  ; Loop until the user exits.
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop

      Case $idButton
        If GUICtrlRead($idButton) = "Remove dotted focus rectangle" Then
          GUICtrlSetData( $idButton, "Add dotted focus rectangle" )
          GUICtrlSendMsg( $idListview, $WM_CHANGEUISTATE, 65537, 0 )
          ; 65537 = _WinAPI_MakeLong( 1, 1 ), 1 = UIS_SET, 1 = UISF_HIDEFOCUS
        Else
          GUICtrlSetData( $idButton, "Remove dotted focus rectangle" )
          GUICtrlSendMsg( $idListview, $WM_CHANGEUISTATE, 65538, 0 )
          ; 65538 = _WinAPI_MakeLong( 2, 1 ), 2 = UIS_CLEAR, 1 = UISF_HIDEFOCUS
        EndIf

      Case $idListview
        MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)

    EndSwitch
  WEnd
EndFunc   ;==>Example

Select an item and click empty space in the listview to see the dotted focus rectangle. Click the button. Repeat select item and click empty space. WM_CHANGEUISTATE.

Share this post


Link to post
Share on other sites

#26 ·  Posted

LarsJ,

Nice to be proved wrong - yet again!

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

#27 ·  Posted

On 24/1/2017 at 3:59 PM, LarsJ said:

If you know how it's close to being trivial. This is the example for GUICtrlCreateListView in the help file:

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

Example()

Func Example()
  GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
  GUISetBkColor(0x00E0FFFF) ; will change background color

  Local $idListview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
  Local $idButton = GUICtrlCreateButton("Remove dotted focus rectangle", 10, 170, 200, 20)
  Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
  Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
  Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
  GUICtrlCreateInput("", 20, 200, 150)
  GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
  GUISetState(@SW_SHOW)
  GUICtrlSetData($idItem2, "ITEM1")
  GUICtrlSetData($idItem3, "||COL33")
  GUICtrlDelete($idItem1)

  ; Loop until the user exits.
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop

      Case $idButton
        If GUICtrlRead($idButton) = "Remove dotted focus rectangle" Then
          GUICtrlSetData( $idButton, "Add dotted focus rectangle" )
          GUICtrlSendMsg( $idListview, $WM_CHANGEUISTATE, 65537, 0 )
          ; 65537 = _WinAPI_MakeLong( 1, 1 ), 1 = UIS_SET, 1 = UISF_HIDEFOCUS
        Else
          GUICtrlSetData( $idButton, "Remove dotted focus rectangle" )
          GUICtrlSendMsg( $idListview, $WM_CHANGEUISTATE, 65538, 0 )
          ; 65538 = _WinAPI_MakeLong( 2, 1 ), 2 = UIS_CLEAR, 1 = UISF_HIDEFOCUS
        EndIf

      Case $idListview
        MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)

    EndSwitch
  WEnd
EndFunc   ;==>Example

Select an item and click empty space in the listview to see the dotted focus rectangle. Click the button. Repeat select item and click empty space. WM_CHANGEUISTATE.

Thx, I tried the Melba UDF "NoFocusLines.au3" without success, now I tried your trick in my script but it does not work, I used it after Case $NM_CLICK, but the dotted focus persist.:no:

   

Share this post


Link to post
Share on other sites

#28 ·  Posted

rootx,

Quote

I tried the Melba UDF "NoFocusLines.au3" without success

I told you above that:

Quote

My _NoFocusLines UDF will do the trick for button, sllder, radio and checkbox  controls

So where did you get the idea that it could ever work on a ListView?

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

#29 ·  Posted

8 minutes ago, Melba23 said:

rootx,

I told you above that:

So where did you get the idea that it could ever work on a ListView?

M23

Right, your UDF works perfectly with other elements, and I used it on my script, THX for share your UDF Melba. I meant that I could not resolve the listview with the LarsJ trick. THX you guys.

Share this post


Link to post
Share on other sites

#30 ·  Posted

rootx,

Sorry for the misunderstanding - glad you found my UDF useful.

Did LarsJ's example work for you? If so, then post the code where you tried to integrate it into your script and perhaps we can spot where it is going wrong.

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

#31 ·  Posted

On 25/1/2017 at 9:20 PM, Melba23 said:

rootx,

Sorry for the misunderstanding - glad you found my UDF useful.

Did LarsJ's example work for you? If so, then post the code where you tried to integrate it into your script and perhaps we can spot where it is going wrong.

M23

Sorry for the delay, I was sick, I need help to understand how to use LarsJ trick on my code, I tried without success, THX thanks for your patience.

Look at Line 138.

#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <StaticConstants.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Date.au3>
#include <IE.au3>
#include "GUIListViewEx.au3"

HotKeySet("{ESC}", "On_Exit")

Global $bChanged

;Graphics
Global $icod = @ScriptDir & "\img\defico.jpg"
Global $bg = @ScriptDir & "\img\def.jpg"
Global $ini = @ScriptDir & "\ini.ini"

For $z = 1 to 4
    IniWriteSection($ini,@ScriptDir&"\data\"&$z,"")
Next

$sect = IniReadSectionNames($ini)

For $s = 1 To UBound($sect) - 1
    IniWrite($ini,$sect[$s],"name",$s)
    IniWrite($ini,$sect[$s],"img",@ScriptDir&"\img\"&$s&".jpg")
    IniWrite($ini,$sect[$s],"icon",@ScriptDir&"\ico\"&$s&".ico")
    IniWrite($ini,$sect[$s],"background",@ScriptDir&"\img\"&$s&".jpg")
Next

$GUIH="600"
$GUIW="1024"
$LsX="172"
$LsY="33"
$LsW="340"
$LsH="481"

$Xcolor = "0x0000FFFF"
$Xfcolor = "0x0000FFFF"

_GDIPlus_Startup()

$Form1 = GUICreate("My LIB", 1024, 600, -1, -1)
GUICtrlSetDefColor($Xfcolor)
GUICtrlSetDefBkColor($Xcolor)

$Pic2 = GUICtrlCreatePic($bg, 820, 10, 200, 200, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER))
;Create listview
$hListView = _GUICtrlListView_Create($Form1, "", 0, 0, 320, 600)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
; block resizing of columns
ControlDisable($Form1, "", HWnd(_GUICtrlListView_GetHeader($hListView)))

;_GUICtrlListView_SetBkColor($hListView, $Xcolor)
;_GUICtrlListView_SetTextBkColor($hListView, $Xcolor)
;_GUICtrlListView_SetTextColor($hListView, 0x0000000)

;Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "", 320)
_GUICtrlListView_InsertColumn($hListView, 1, "Path", 0)

_GUIListViewEx_MsgRegister(False) ;<---------------------------------------

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

GUISetState(@SW_SHOW)

;Slide Effect
Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($Form1)
;clip control elements
Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $guiw, $guih)
Global $hChild = _WinAPI_GetWindow($Form1, $GW_CHILD)
Global $aRect
Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGfx, $hRegion)
_GDIPlus_RegionDispose($hRegion)
Global $hBmp1 = _GDIPlus_ImageLoadFromFile($bg)
_GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp1, 0, 0, $guiw, $guih)

read()

_GUICtrlListView_RegisterSortCallBack($hListView)

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _GDIPlus_ImageDispose($hBmp1)
                    _GDIPlus_GraphicsDispose($hGfx)
                    _GDIPlus_Shutdown()
            EndSwitch
    EndSwitch
WEnd

; ========================================================
; This thing is responcible for click events
; ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom

        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If DllStructGetData($tInfo, "Index") = -1 Then
                        ;ConsoleWrite("no item" & @CRLF)
                    Else
                        GUICtrlSendMsg($hListView, $WM_CHANGEUISTATE, 65537, 0 );<--------------------------------------------???
                        Local $iItemText = _GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), 1)
                        $pics = IniRead($ini, $iItemText, "img", "")
                        If FileExists($pics) Then
                            GUICtrlSetImage($Pic2, $pics)
                        Else
                            GUICtrlSetImage($Pic2, $icod)
                        EndIf
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index), '|')
                        $itemx = $item[1]
                        $item2 = IniRead($ini, $iItemText, "background", "")
                        Local $n = 1, $guihx = $guih + 50
                        If FileExists($item2) Then
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemText, "background", ""))
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        Else
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile($bg)
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        EndIf
                    EndIf

                    Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    ; Get current selection
                    $aLastSel = StringSplit(_GUIListViewEx_GetLastSelectedItem(), "|")
                    Switch $iKey
                        Case 38
                            ; Move up unless at top
                            $iCurrItem = $aLastSel[2] - 1
                            If $iCurrItem < 0 Then
                                $iCurrItem = 0
                            EndIf
                            _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem)
                        Case 40
                            ; Move down unless at bottom
                            $iCurrItem = $aLastSel[2] + 1
                            If $iCurrItem >= _GUICtrlListView_GetItemCount($hWndFrom) Then
                                $iCurrItem = _GUICtrlListView_GetItemCount($hWndFrom) - 1
                            EndIf
                            _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem)
                    EndSwitch
            EndSwitch
    EndSwitch

    $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam);<---------------------------------------
    Return $iRet;<---------------------------------------
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func read()
    Local $tot = 0
    If FileExists($ini) Then
        $hImage = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()
        $aArrays = IniReadSectionNames($ini)
        _ArrayColInsert($aArrays, 1)
        For $s = 1 To UBound($aArrays) - 1
            $aArrays[$s][1] = StringRegExp($aArrays[$s][0], '.*\\(.*)\\', 1)[0]
        Next
        _ArrayColDelete($aArrays, 1, True)
        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1
                $n = IniRead($ini, $aArrays[$i], "name", "")
                $z = IniRead($ini, $aArrays[$i], "icon", "")
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled = _GDIPlus_ImageResize($hBitmap, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap)
                $ico = _GUIImageList_Add($hImage, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($hListView, $hImage, 1)
                _GUICtrlListView_AddItem($hListView, $n, $ico)
                _GUICtrlListView_AddSubItem($hListView, $i - 1, $aArrays[$i], 1)
                $tot += 1
            Next

                $aLVArray = _GUIListViewEx_ReadToArray($hListView);<---------------------------------------
                $iLV_Index = _GUIListViewEx_Init($hListView, $aLVArray, 0, 0, True, 32 + 512);<---------------------------------------
                ; Set required colours for ListView elements - change = pink field when selected;<---------------------------------------
                Local $aSelCol[4] = [Default, Default, Default, "0xFFCCCC"];<---------------------------------------
                _GUIListViewEx_SetDefColours($iLV_Index, $aSelCol);<---------------------------------------


            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read

Func _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)

    ; Check valid index
    Switch $iLV_Index
        Case 1 To $aGLVEx_Data[0][0]
            ; Valid index
        Case Else
            ; Get active ListView
            $iLV_Index = _GUIListViewEx_GetActive()
            ; If no ListView active
            If $iLV_Index = 0 Then Return SetError(1, 0, "")
    EndSwitch

    ; Read last selected item
    Local $iRow = $aGLVEx_Data[$iLV_Index][20]
    Local $iCol = $aGLVEx_Data[$iLV_Index][21]
    ; Check selection has been made
    If $iRow = -1 Or $iCol = -1 Then Return SetError(2, 0, "")
    ; Return selection details
    Return $iLV_Index & "|" & $iRow & "|" & $iCol

EndFunc

 

Share this post


Link to post
Share on other sites

#32 ·  Posted

rootx,

Firstly you are creating the ListView using the UDF, so you cannot use GUICtrlSendMsg - the creation function returns a handle and not a ControlID - you need to use _SendMessage instead.

Here is your script amended to use a HotKey to toggle the focus lines:

#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <StaticConstants.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <Date.au3>
#include <IE.au3>
#include "GUIListViewEx.au3"

HotKeySet("{ESC}", "On_Exit")

HotKeySet("^f", "_FocusSwitch")
Global $fFocus = False

Global $bChanged

;Graphics
Global $icod = @ScriptDir & "\img\defico.jpg"
Global $bg = @ScriptDir & "\img\def.jpg"
Global $ini = @ScriptDir & "\ini.ini"

For $z = 1 to 4
    IniWriteSection($ini,@ScriptDir&"\data\"&$z,"")
Next

$sect = IniReadSectionNames($ini)

For $s = 1 To UBound($sect) - 1
    IniWrite($ini,$sect[$s],"name",$s)
    IniWrite($ini,$sect[$s],"img",@ScriptDir&"\img\"&$s&".jpg")
    IniWrite($ini,$sect[$s],"icon",@ScriptDir&"\ico\"&$s&".ico")
    IniWrite($ini,$sect[$s],"background",@ScriptDir&"\img\"&$s&".jpg")
Next

$GUIH="600"
$GUIW="1024"
$LsX="172"
$LsY="33"
$LsW="340"
$LsH="481"

$Xcolor = "0x0000FFFF"
$Xfcolor = "0x0000FFFF"

_GDIPlus_Startup()

$Form1 = GUICreate("My LIB", 1024, 600, -1, -1)
GUICtrlSetDefColor($Xfcolor)
GUICtrlSetDefBkColor($Xcolor)

$Pic2 = GUICtrlCreatePic($bg, 820, 10, 200, 200, BitOR($GUI_SS_DEFAULT_PIC, $SS_CENTERIMAGE, $SS_SUNKEN, $WS_BORDER))
;Create listview
$hListView = _GUICtrlListView_Create($Form1, "", 0, 0, 320, 600)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_AUTOARRANGE, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_SUBITEMIMAGES))
; block resizing of columns
ControlDisable($Form1, "", HWnd(_GUICtrlListView_GetHeader($hListView)))


;_GUICtrlListView_SetBkColor($hListView, $Xcolor)
;_GUICtrlListView_SetTextBkColor($hListView, $Xcolor)
;_GUICtrlListView_SetTextColor($hListView, 0x0000000)

;Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "", 320)
_GUICtrlListView_InsertColumn($hListView, 1, "Path", 0)

_GUIListViewEx_MsgRegister(False) ;<---------------------------------------

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')

GUISetState(@SW_SHOW)

;Slide Effect
Global $hGfx = _GDIPlus_GraphicsCreateFromHWND($Form1)
;clip control elements
Global $hRegion = _GDIPlus_RegionCreateFromRect(0, 0, $guiw, $guih)
Global $hChild = _WinAPI_GetWindow($Form1, $GW_CHILD)
Global $aRect
Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, $aRect[0], $aRect[1], $aRect[2], $aRect[3], 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
Until Not $hChild
_GDIPlus_GraphicsSetClipRegion($hGfx, $hRegion)
_GDIPlus_RegionDispose($hRegion)
Global $hBmp1 = _GDIPlus_ImageLoadFromFile($bg)
_GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp1, 0, 0, $guiw, $guih)

read()

_GUICtrlListView_RegisterSortCallBack($hListView)

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    _GDIPlus_ImageDispose($hBmp1)
                    _GDIPlus_GraphicsDispose($hGfx)
                    _GDIPlus_Shutdown()
            EndSwitch
    EndSwitch
WEnd

Func _FocusSwitch()

    $fFocus = Not $fFocus
    If $fFocus Then
        _SendMessage($hListView, $WM_CHANGEUISTATE, 65537, 0)
    Else
        _SendMessage($hListView, $WM_CHANGEUISTATE, 65538, 0)
    EndIf
EndFunc

; ========================================================
; This thing is responcible for click events
; ========================================================
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom

        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; The user has clicked the left mouse button within the control
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $Index = DllStructGetData($tInfo, "Index")
                    If DllStructGetData($tInfo, "Index") = -1 Then
                        ;ConsoleWrite("no item" & @CRLF)
                    Else
                        ;GUICtrlSendMsg($hListView, $WM_CHANGEUISTATE, 65537, 0 );<--------------------------------------------???
                        Local $iItemText = _GUICtrlListView_GetItemText($hListView, DllStructGetData($tInfo, "Index"), 1)
                        $pics = IniRead($ini, $iItemText, "img", "")
                        If FileExists($pics) Then
                            GUICtrlSetImage($Pic2, $pics)
                        Else
                            GUICtrlSetImage($Pic2, $icod)
                        EndIf
                        $item = StringSplit(_GUICtrlListView_GetItemTextString($hListView, $Index), '|')
                        $itemx = $item[1]
                        $item2 = IniRead($ini, $iItemText, "background", "")
                        Local $n = 1, $guihx = $guih + 50
                        If FileExists($item2) Then
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile(IniRead($ini, $iItemText, "background", ""))
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        Else
                            Local $hBmp2 = _GDIPlus_ImageLoadFromFile($bg)
                            For $x = -$guiw To 0 Step 50
                                _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp2, 0, $x, $guiw, $guihx)
                            Next
                            _GDIPlus_ImageDispose($hBmp2)
                        EndIf
                    EndIf

                    Case $LVN_KEYDOWN
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
                    $iKey = DllStructGetData($tInfo, "VKey")
                    ; Get current selection
                    $aLastSel = StringSplit(_GUIListViewEx_GetLastSelectedItem(), "|")
                    Switch $iKey
                        Case 38
                            ; Move up unless at top
                            $iCurrItem = $aLastSel[2] - 1
                            If $iCurrItem < 0 Then
                                $iCurrItem = 0
                            EndIf
                            _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem)
                        Case 40
                            ; Move down unless at bottom
                            $iCurrItem = $aLastSel[2] + 1
                            If $iCurrItem >= _GUICtrlListView_GetItemCount($hWndFrom) Then
                                $iCurrItem = _GUICtrlListView_GetItemCount($hWndFrom) - 1
                            EndIf
                            _GUICtrlListView_ClickItem($hWndFrom, $iCurrItem)
                    EndSwitch
            EndSwitch
    EndSwitch

    $iRet = _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $iwParam, $ilParam);<---------------------------------------
    Return $iRet;<---------------------------------------
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func read()
    Local $tot = 0
    If FileExists($ini) Then
        $hImage = _GUIImageList_Create(48, 48, 5, 1)
        _GDIPlus_Startup()
        $aArrays = IniReadSectionNames($ini)
        _ArrayColInsert($aArrays, 1)
        For $s = 1 To UBound($aArrays) - 1
            $aArrays[$s][1] = StringRegExp($aArrays[$s][0], '.*\\(.*)\\', 1)[0]
        Next
        _ArrayColDelete($aArrays, 1, True)
        If Not @error Then
            For $i = 1 To UBound($aArrays) - 1
                $n = IniRead($ini, $aArrays[$i], "name", "")
                $z = IniRead($ini, $aArrays[$i], "icon", "")
                ;load icon and upscale the icon to 48x48 pixels
                $hBitmap = _GDIPlus_BitmapCreateFromFile($z)
                $hBitmap_scaled = _GDIPlus_ImageResize($hBitmap, 48, 48)
                $hBitmap_GDI = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap_scaled)
                _GDIPlus_BitmapDispose($hBitmap)
                $ico = _GUIImageList_Add($hImage, $hBitmap_GDI)
                _GUICtrlListView_SetImageList($hListView, $hImage, 1)
                _GUICtrlListView_AddItem($hListView, $n, $ico)
                _GUICtrlListView_AddSubItem($hListView, $i - 1, $aArrays[$i], 1)
                $tot += 1
            Next

                $aLVArray = _GUIListViewEx_ReadToArray($hListView);<---------------------------------------
                $iLV_Index = _GUIListViewEx_Init($hListView, $aLVArray, 0, 0, True, 32 + 512);<---------------------------------------
                ; Set required colours for ListView elements - change = pink field when selected;<---------------------------------------
                Local $aSelCol[4] = [Default, Default, Default, "0xFFCCCC"];<---------------------------------------
                _GUIListViewEx_SetDefColours($iLV_Index, $aSelCol);<---------------------------------------


            _GDIPlus_Shutdown()
        EndIf
    EndIf
EndFunc   ;==>read

Func _GUIListViewEx_GetLastSelectedItem($iLV_Index = 0)

    ; Check valid index
    Switch $iLV_Index
        Case 1 To $aGLVEx_Data[0][0]
            ; Valid index
        Case Else
            ; Get active ListView
            $iLV_Index = _GUIListViewEx_GetActive()
            ; If no ListView active
            If $iLV_Index = 0 Then Return SetError(1, 0, "")
    EndSwitch

    ; Read last selected item
    Local $iRow = $aGLVEx_Data[$iLV_Index][20]
    Local $iCol = $aGLVEx_Data[$iLV_Index][21]
    ; Check selection has been made
    If $iRow = -1 Or $iCol = -1 Then Return SetError(2, 0, "")
    ; Return selection details
    Return $iLV_Index & "|" & $iRow & "|" & $iCol

EndFunc

 

There is fairly fundamental difference between handles and ControlIDs - I have explained it many times before - and you really need to be sure you understand it.

Please ask if you have any questions.

M23

1 person likes this

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

#33 ·  Posted

Thx, your post explains very well this important difference, now I understand.

 

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

    • mpower
      By mpower
      Hi guys,
      So I am facing an issue with my Listview control flickering like crazy when using the Modern GUI UDF.
      I understand that the reson is because Listviews do not play nice with the $WS_EX_COMPOSITED extended style which is necessary to prevent the rest of the GUI components flickering on resizing.
      I am looking for suggestions on how I can overcome the flickering issue without having to remove the Listview header (as I need the header to allow column resizing and sorting).
      The reproducer is here and the lightly modified Modern GUI UDF is attached as a zip (I added $WS_CLIPCHILDREN and $WS_EX_COMPOSITED to the _Metro_CreateGUI() function in order to stop flickering of other controls like buttons/labels/toggles etc).
      ;!Highly recommended for improved overall performance and responsiveness of the GUI effects etc.! (after compiling): #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so /rm /pe ;Required if you want High DPI scaling enabled. (Also requries _Metro_EnableHighDPIScaling()) #AutoIt3Wrapper_Res_HiDpi=y #include-once #NoTrayIcon #include "MetroGUI-UDF\MetroGUI_UDF.au3" #include <GuiListView.au3> $gui = _Metro_CreateGUI("example", 800, 600, -1, -1, True) ;Add/create control buttons to the GUI $Control_Buttons = _Metro_AddControlButtons(True, True, True, True, False) ;CloseBtn = True, MaximizeBtn = True, MinimizeBtn = True, FullscreenBtn = True, MenuBtn = True ;Set variables for the handles of the GUI-Control buttons. (Above function always returns an array this size and in this order, no matter which buttons are selected. $GUI_CLOSE_BUTTON = $Control_Buttons[0] $GUI_MAXIMIZE_BUTTON = $Control_Buttons[1] $GUI_RESTORE_BUTTON = $Control_Buttons[2] $GUI_MINIMIZE_BUTTON = $Control_Buttons[3] $GUI_FULLSCREEN_BUTTON = $Control_Buttons[4] $GUI_FSRestore_BUTTON = $Control_Buttons[5] ;====================================================================================================================================================================== $Button1 = _Metro_CreateButtonEx("Add new item(s)", 20, 20, 130, 50) $Button2 = _Metro_CreateButtonEx("Edit item(s)", 170, 20, 130, 50) $ListView2 = GUICtrlCreateListView("", 0, 86, 800, 400, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) _GUICtrlListView_SetExtendedListViewStyle($ListView2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES, $LVS_EX_FLATSB)) For $i = 0 to 8 _GUICtrlListView_AddColumn($ListView2, "col " &$i) Next _GUICtrlListView_SetBkColor($ListView2, 0xF3F3F3) _GUICtrlListView_SetTextBkColor($ListView2, 0xF3F3F3) ;Set resizing options for the controls so they don't change in size or position. This can be customized to match your gui perfectly for resizing. See AutoIt Help file. GUICtrlSetResizing($Button1, 768 + 2 + 32) GUICtrlSetResizing($Button2, 768 + 2 + 32) GUICtrlSetResizing($ListView2, 102) GUISetState(@SW_SHOW) While 1 _Metro_HoverCheck_Loop($gui) ;This hover check has to be added to the main While loop, otherwise the hover effects won't work. $nMsg = GUIGetMsg() Switch $nMsg ;=========================================Control-Buttons=========================================== Case $GUI_EVENT_CLOSE, $GUI_CLOSE_BUTTON _Metro_GUIDelete($gui) ;Delete GUI/release resources, make sure you use this when working with multiple GUIs! Exit Case $GUI_MAXIMIZE_BUTTON GUISetState(@SW_MAXIMIZE) Case $GUI_RESTORE_BUTTON GUISetState(@SW_RESTORE) Case $GUI_MINIMIZE_BUTTON GUISetState(@SW_MINIMIZE) Case $GUI_FULLSCREEN_BUTTON, $GUI_FSRestore_BUTTON _Metro_FullscreenToggle($gui, $Control_Buttons) EndSwitch WEnd Any suggestions would be greately appreciated.
      Cheers!
      MetroGUI-UDF.zip
    • Adrian123
      By Adrian123
      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
    • rootx
      By rootx
      I would like to hide the header in the listview, but I did not find anything in the help and in the forum, you have some advice, thanks.
    • Clemens
      By Clemens
      Hi there,
      I have a small hopefully quick fixable issue with reading information from my ListView:
      So in fact I just want to have information about which items are selected, so I'm using
      msgbox(0 , "return", GUICtrlRead($myListView), 1)
      but unfortunately it only returns me either the first item id or if this is not selected the second item id, or if this is not selected the third, etc. or 0 if none is selected.
      Anybody has an idea how to get the full picture of my >>multiple Items selected<< ListView?
      Thanks in advance!
      Clemens
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys