Jump to content

GUICtrlCreateListView() and _GUICtrlListView_Create() problem


Recommended Posts

Having problems with GUICtrlCreateListView() and _GUICtrlListView_Create(). 

 

But if I use either of them, sorting (by clicking the header to arrange the list) using GUICtrlCreateListView() it works. But for _GUICtrlListView_Create() it won't. Same thing happens for editing the list using GUICtrlCreateListView().

 

;GUICtrlCreateListView() sorting works. Editing fails.

 

#include <GuiEdit.au3>
#include <GUIListViewEx_Mod.au3>
#include <GuiImageList.au3>
#include <String.au3>
#include <Misc.au3>
#include <File.au3>
#include <Timers.au3>
#include <WinAPI.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListviewConstants.au3>
 
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
 
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
Global $aIcons[3] = [0, 3, 6], $font = "Gill Sans"
 
Global $hGUI = GUICreate("TEST CLIENT", 1600, 900)
 
$hListView = GUICtrlCreateListView("TEST1|TEST2|TEST3", 5, 100, 938, 500)
 
;$hListView = _GUICtrlListView_Create($hGUI, "TEST1|TEST2|TEST3", 5, 100, 938, 500, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_BORDERSELECT, $LVS_EX_ONECLICKACTIVATE, $LVS_EDITLABELS,$WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE))
 
$hNM_DBCLK = GUICtrlCreateDummy()
$hEN_KILLFOCUS = GUICtrlCreateDummy()
 
_AddRow($hListView, "1|A|NAME1", $aIcons, 1)
_AddRow($hListView, "2|B|NAME2", $aIcons, 2)
_AddRow($hListView, "3|C|NAME3", $aIcons, 3)
 
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
GUISetState(@SW_SHOW, $hGUI)
 
_GUICtrlListView_RegisterSortCallBack($hListView)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hNM_DBCLK
            Start_EditingLV()
        Case $hEN_KILLFOCUS
            End_EditingLV()
Case $hListView
_GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
    EndSwitch
WEnd
 
_GUICtrlListView_UnRegisterSortCallBack($hListView)
GUIDelete()
 
;===============================================================
 
Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
Local $aItem = StringSplit($sItem, "|")
Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 99999)
_GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)
 
For $x = 2 To $aItem[0]
_GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
_GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
Next
EndFunc   ;==>_AddRow
 
 
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode
 
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
 
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
                    GUICtrlSendToDummy($hNM_DBCLK)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
 
Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
 
 
Local $stRect = DllStructCreate("int;int;int;int")
 
DllStructSetData($stRect, 1, $nLeft)
DllStructSetData($stRect, 2, $nTop)
DllStructSetData($stRect, 3, $nRight)
DllStructSetData($stRect, 4, $nBottom)
 
DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc
 
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
 
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
                    GUICtrlSendToDummy($hEN_KILLFOCUS)
EndSwitch
EndSwitch
 
Return $GUI_RUNDEFMSG
EndFunc
 
Func Start_EditingLV()
    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    Local $hRect = ControlGetPos($hGUI, "", $hListView)
 
    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
        $Item = $aHit[0]
        $SubItem = 0
        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
        $Item = $aHit[0]
        $SubItem = $aHit[1]
        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) ;dldl
    Else
        Return $GUI_RUNDEFMSG
    EndIf
 
    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + ($hRect[0] + 3), $aRect[1] + $hRect[1], $iLen + 10, 17, $Style)
 
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
    FrameRect($hDC, 0,0, $iLen + 10 , 17, $hBrush)
    HotKeySet("{ENTER}", "End_EditingLV")
 
EndFunc
 
Func End_EditingLV()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    ControlEnable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    $Item = -1
    $SubItem = 0
    HotKeySet("{ENTER}")
EndFunc
 

 

Link to comment
Share on other sites

From this example: _GUICtrlListView_Create() was used and editing the list works, sorting the list fails.

#include <GuiEdit.au3>
#include <GUIListViewEx_Mod.au3>
#include <GuiImageList.au3>
#include <String.au3>
#include <Misc.au3>
#include <File.au3>
#include <Timers.au3>
#include <WinAPI.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <ListviewConstants.au3>
 
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
 
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
Global $aIcons[3] = [0, 3, 6], $font = "Gill Sans"
 
Global $hGUI = GUICreate("TEST CLIENT", 1600, 900)
 
;$hListView = GUICtrlCreateListView("TEST1|TEST2|TEST3", 5, 100, 938, 500)
 
$hListView = _GUICtrlListView_Create($hGUI, "TEST1|TEST2|TEST3", 5, 100, 938, 500, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_BORDERSELECT, $LVS_EX_ONECLICKACTIVATE, $LVS_EDITLABELS,$WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE))
 
$hNM_DBCLK = GUICtrlCreateDummy()
$hEN_KILLFOCUS = GUICtrlCreateDummy()
 
_AddRow($hListView, "1|A|NAME1", $aIcons, 1)
_AddRow($hListView, "2|B|NAME2", $aIcons, 2)
_AddRow($hListView, "3|C|NAME3", $aIcons, 3)
 
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
GUISetState(@SW_SHOW, $hGUI)
 
_GUICtrlListView_RegisterSortCallBack($hListView)
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hNM_DBCLK
            Start_EditingLV()
        Case $hEN_KILLFOCUS
            End_EditingLV()
Case $hListView
_GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
    EndSwitch
WEnd
 
_GUICtrlListView_UnRegisterSortCallBack($hListView)
GUIDelete()
 
;===============================================================
 
Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
Local $aItem = StringSplit($sItem, "|")
Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 99999)
_GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)
 
For $x = 2 To $aItem[0]
_GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
_GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
Next
EndFunc   ;==>_AddRow
 
 
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode
 
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
 
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
                    GUICtrlSendToDummy($hNM_DBCLK)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
 
Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
 
 
Local $stRect = DllStructCreate("int;int;int;int")
 
DllStructSetData($stRect, 1, $nLeft)
DllStructSetData($stRect, 2, $nTop)
DllStructSetData($stRect, 3, $nRight)
DllStructSetData($stRect, 4, $nBottom)
 
DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc
 
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
 
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
                    GUICtrlSendToDummy($hEN_KILLFOCUS)
EndSwitch
EndSwitch
 
Return $GUI_RUNDEFMSG
EndFunc
 
Func Start_EditingLV()
    ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    Local $hRect = ControlGetPos($hGUI, "", $hListView)
 
    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
        $Item = $aHit[0]
        $SubItem = 0
        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
        $Item = $aHit[0]
        $SubItem = $aHit[1]
        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem) ;dldl
    Else
        Return $GUI_RUNDEFMSG
    EndIf
 
    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + ($hRect[0] + 3), $aRect[1] + $hRect[1], $iLen + 10, 17, $Style)
 
    _GUICtrlEdit_SetSel($hEdit, 0, -1)
    _WinAPI_SetFocus($hEdit)
    $hDC = _WinAPI_GetWindowDC($hEdit)
    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
    FrameRect($hDC, 0,0, $iLen + 10 , 17, $hBrush)
    HotKeySet("{ENTER}", "End_EditingLV")
 
EndFunc
 
Func End_EditingLV()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($hEdit, $hDC)
    _WinAPI_DestroyWindow($hEdit)
    ControlEnable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($hListView)))
 
    $Item = -1
    $SubItem = 0
    HotKeySet("{ENTER}")
EndFunc
 
Edited by NearValue
Link to comment
Share on other sites

Are you sure that you posted the right scripts? I can't edit either of them at all, but it sorts just fine on both.

 

BTW, unrelated to the problem. Your extended style settings will NOT work as you expect. $LVS_EX_GRIDLINES and $WS_EX_DLGMODALFRAME are the same value, and only the first one should be used as a ListView style setting, $WS_EX styles are windows style, $LVS_EX are listview styles.

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

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

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

Link to comment
Share on other sites

GUIGetMsg works with control IDs returned by native functions, _GUICtrlListview_Create returns a handle and not a control ID so you can't use GUIGetMsg with a UDF created control, such as the LV you're using.

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

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

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...