Sign in to follow this  
Followers 0
johnmcloud

Problem with _GUICtrlListView

9 posts in this topic

Hi guys, this is the script:

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>

Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0, $Number = 0, $hMenu
Global Enum $idMoveUp = 1000, $idMoveDown, $idDelete
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)

HotKeySet("{DELETE}", "Delete_Item")
HotKeySet("{UP}", "Move_Up")
HotKeySet("{DOWN}", "Move_Down")

$GUI = GUICreate("_GUICtrlListView_Example", 262, 351, -1, -1)
$hListView = _GUICtrlListView_Create($GUI, "N°|Name|Subject", 5, 5, 250, 272)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
_GUICtrlListView_SetColumnWidth($hListView, 0, 35)
_GUICtrlListView_SetColumnWidth($hListView, 1, 107)
_GUICtrlListView_SetColumnWidth($hListView, 2, 108)
$Label = GUICtrlCreateLabel("Name", 13, 290, 67, 17)
$Add = GUICtrlCreateButton("Add", 90, 315, 80, 25)
$Info = GUICtrlCreateInput("Subject", 88, 286, 83, 21)
$Save = GUICtrlCreateButton("Save", 174, 284, 80, 25)
GUISetState(@SW_SHOW)

$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Move Up", $idMoveUp)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Move Down", $idMoveDown)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "Delete", $idDelete)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Add
   Add_Item()
  Case $Save
   Save_List()
EndSwitch
WEnd

Func Add_Item()
$Number += 1
_GUICtrlListView_AddItem($hListView, $Number)
_GUICtrlListView_AddSubItem($hListView, $Number - 1, GUICtrlRead($Label), 1)
_GUICtrlListView_AddSubItem($hListView, $Number - 1, GUICtrlRead($Info), 2)
EndFunc   ;==>Add_Item

Func Delete_Item()
_GUICtrlListView_DeleteItemsSelected($hListView)
_Arrange_Numbers()
EndFunc   ;==>Delete_Item

Func _Arrange_Numbers()
Dim $iCount = 0
$Total_Number = _GUICtrlListView_GetItemCount($hListView) - 1
For $i = 0 To $Total_Number
   $iCount += 1
  _GUICtrlListView_SetItemText($hListView, $i, $iCount)
Next
EndFunc

Func Save_List()
Local $Save = FileSaveDialog("Save", @WorkingDir, "Txt Files (*.txt)", 2, "Test_File_" & @MDAY & "-" & @MON & "-" & @YEAR & "_" & @HOUR & "-" & @MIN)
If @error Then
  ConsoleWrite("Abort")
Else
  $List = FileOpen($Save & ".txt", 2)
  $Number_items = _GUICtrlListView_GetItemCount($hListView)
  For $i = 0 To $Number_items - 1 Step +1
   $output = StringReplace(_GUICtrlListView_GetItemTextString($hListView, $i), "|", " - ")
   FileWriteLine($List, $output)
  Next
  FileClose($List)
EndIf
EndFunc   ;==>Save_List

Func Move_Up()
Local $Sel, $aArrayListView
$aArrayListView = _GUICtrlListView_CreateArray($hListView)
$Sel = _GUICtrlListView_GetNextItem($hListView)
If $Sel > 0 Then
  Local $SelItem, $NxtItem
  $SelItem = _GUICtrlListView_GetItemTextArray($hListView, $Sel)
  $PrvItem = _GUICtrlListView_GetItemTextArray($hListView, $Sel - 1)
  For $i = 1 To $SelItem[0]
   $aArrayListView[$Sel][$i - 1] = $PrvItem[$i]
   $aArrayListView[$Sel - 1][$i - 1] = $SelItem[$i]
   _GUICtrlListView_SetItemText($hListView, $Sel, $PrvItem[$i], $i - 1)
   _GUICtrlListView_SetItemText($hListView, $Sel - 1, $SelItem[$i], $i - 1)
   _GUICtrlListView_SetItemSelected($hListView, $Sel - 1)
  Next
EndIf
_Arrange_Numbers()
EndFunc   ;==>Move_Up

Func Move_Down()
Local $Sel, $Lst, $aArrayListView
$aArrayListView = _GUICtrlListView_CreateArray($hListView)
$Sel = _GUICtrlListView_GetNextItem($hListView)
$Lst = _GUICtrlListView_GetItemCount($hListView) - 1
If $Sel < $Lst And $Sel <> -1 Then
  Local $SelItem, $NxtItem
  $SelItem = _GUICtrlListView_GetItemTextArray($hListView, $Sel)
  $NxtItem = _GUICtrlListView_GetItemTextArray($hListView, $Sel + 1)
  For $i = 1 To $SelItem[0]
   $aArrayListView[$Sel][$i - 1] = $NxtItem[$i]
   $aArrayListView[$Sel + 1][$i - 1] = $SelItem[$i]
   _GUICtrlListView_SetItemText($hListView, $Sel, $NxtItem[$i], $i - 1)
   _GUICtrlListView_SetItemText($hListView, $Sel + 1, $SelItem[$i], $i - 1)
   _GUICtrlListView_SetItemSelected($hListView, $Sel + 1)
  Next
EndIf
_Arrange_Numbers()
EndFunc   ;==>Move_Down

Func _GUICtrlListView_CreateArray($hListView, $sDelimeter = '|')
Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListView)
If $iColumnCount < 3 Then
  $iDim = 3 - $iColumnCount
EndIf
If $sDelimeter = Default Then
  $sDelimeter = '|'
EndIf
Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
For $i = 0 To $iColumnCount - 1
  $aColumns = _GUICtrlListView_GetColumn($hListView, $i)
  $aReturn[0][2] &= $aColumns[5] & $sDelimeter
Next
$aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))
For $i = 0 To $iItemCount - 1
  For $j = 0 To $iColumnCount - 1
   $aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j)
  Next
Next
Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc   ;==>_GUICtrlListView_CreateArray

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
     Local $aHit = _GUICtrlListView_SubItemHitTest($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)
     Else
      Return $GUI_RUNDEFMSG
     EndIf
     Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
     Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
     $hEdit = _GUICtrlEdit_Create($GUI, $iItemText, $aRect[0] + 3, $aRect[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)
    Case $NM_RCLICK
     $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
     If DllStructGetData($tInfo, "Item") > -1 Then
      _GUICtrlMenu_TrackPopupMenu($hMenu, $GUI)
     EndIf
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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   ;==>FrameRect
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
Switch $lParam
  Case $hEdit
   Switch $iCode
    Case $EN_KILLFOCUS
     Local $iText = _GUICtrlEdit_GetText($hEdit)
     _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
     _WinAPI_DeleteObject($hBrush)
     _WinAPI_ReleaseDC($hEdit, $hDC)
     _WinAPI_DestroyWindow($hEdit)
     $Item = -1
     $SubItem = 0
   EndSwitch
EndSwitch
Switch $wParam
  Case $idMoveUp
   Move_Up()
  Case $idMoveDown
   Move_Down()
  Case $idDelete
   Delete_Item()
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

I have some problem with it, hope someone can give me a solution:

1) The Move_Up and Move_Down fuction, for move items, isn't compatible with $LVS_REPORT and i don't know what is the problem

2) When i double click i can edit the item, but i want to confirm with RETURN key and not clicking outside the item, and i don't know how to do

3) I can't sort item. If i use GUICtrlCreateListView i can sort but i can't double click with editing the item, if i use _GUICtrlListView_Create i can't sort but i can edit the items...

I'm in a dead end

Thanks for any help ;)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Some stuff for you to tinker on :)... the Edit rect seems out of line to me (Win7), but was to lazy to dive into that :lol:...

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>

Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0, $Number = 0, $hMenu
Global Enum $idMoveUp = 1000, $idMoveDown, $idDelete
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)

$hGUI = GUICreate("_GUICtrlListView_Example", 262, 351, -1, -1)
$cListview = GUICtrlCreateListView("N°|Name|Subject", 5, 5, 250, 272)
$hListview = GUICtrlGetHandle($cListview)

_GUICtrlListView_SetExtendedListViewStyle($hListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
_GUICtrlListView_SetColumnWidth($hListview, 0, 35)
_GUICtrlListView_SetColumnWidth($hListview, 1, 107)
_GUICtrlListView_SetColumnWidth($hListview, 2, 108)

$Label = GUICtrlCreateLabel("Name", 13, 290, 67, 17)
$c_Button_Add = GUICtrlCreateButton("Add", 90, 315, 80, 25)
$Info = GUICtrlCreateInput("Subject", 88, 286, 83, 21)
$c_Button_Save = GUICtrlCreateButton("Save", 174, 284, 80, 25)

$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Move Up", $idMoveUp)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Move Down", $idMoveDown)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "Delete", $idDelete)

$c_Dummy_Down = GUICtrlCreateDummy()
$c_Dummy_Up = GUICtrlCreateDummy()
$c_Dummy_Delete = GUICtrlCreateDummy()
$c_Dummy_Enter = GUICtrlCreateDummy()

Local $AccelKeys[4][2] = [["{DELETE}", $c_Dummy_Delete],["{UP}", $c_Dummy_Up],["{DOWN}", $c_Dummy_Down],["{ENTER}", $c_Dummy_Enter]]
GUISetAccelerators($AccelKeys, $hGUI)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListview)]

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $c_Button_Add
Add_Item()
Case $c_Button_Save
Save_List()
Case $c_Dummy_Delete
Delete_Item()
Case $c_Dummy_Down
Move_Down()
Case $c_Dummy_Up
Move_Up()
Case $c_Dummy_Enter
If _WinAPI_GetFocus() = $hEdit Then _WinAPI_SetFocus($hListview) ; fires $EN_KILLFOCUS in WM_COMMAND
Case $cListview
_GUICtrlListView_SimpleSort($hListview, $B_DESCENDING, GUICtrlGetState($cListview))

EndSwitch
WEnd

Func Add_Item()
$Number += 1
_GUICtrlListView_AddItem($hListview, $Number, -1, 9999 + $Number) ; add lparam value, is used for sorting as far as I remember
_GUICtrlListView_AddSubItem($hListview, $Number - 1, GUICtrlRead($Label), 1)
_GUICtrlListView_AddSubItem($hListview, $Number - 1, GUICtrlRead($Info), 2)
EndFunc ;==>Add_Item

Func Delete_Item()
_GUICtrlListView_DeleteItemsSelected($hListview)
_Arrange_Numbers()
EndFunc ;==>Delete_Item

Func _Arrange_Numbers()
Dim $iCount = 0
$Total_Number = _GUICtrlListView_GetItemCount($hListview) - 1
For $i = 0 To $Total_Number
$iCount += 1
_GUICtrlListView_SetItemText($hListview, $i, $iCount)
Next
EndFunc ;==>_Arrange_Numbers

Func Save_List()
Local $Save = FileSaveDialog("Save", @WorkingDir, "Txt Files (*.txt)", 2, "Test_File_" & @MDAY & "-" & @MON & "-" & @YEAR & "_" & @HOUR & "-" & @MIN)
If @error Then
ConsoleWrite("Abort")
Else
$List = FileOpen($Save & ".txt", 2)
$Number_items = _GUICtrlListView_GetItemCount($hListview)
For $i = 0 To $Number_items - 1 Step +1
$output = StringReplace(_GUICtrlListView_GetItemTextString($hListview, $i), "|", " - ")
FileWriteLine($List, $output)
Next
FileClose($List)
EndIf
EndFunc ;==>Save_List

Func Move_Up()
Local $Sel, $aArrayListView
$aArrayListView = _GUICtrlListView_CreateArray($hListview)
$Sel = _GUICtrlListView_GetNextItem($hListview)
If $Sel > 0 Then
Local $SelItem, $NxtItem
$SelItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel)
$PrvItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel - 1)
For $i = 1 To $SelItem[0]
$aArrayListView[$Sel][$i - 1] = $PrvItem[$i]
$aArrayListView[$Sel - 1][$i - 1] = $SelItem[$i]
_GUICtrlListView_SetItemText($hListview, $Sel, $PrvItem[$i], $i - 1)
_GUICtrlListView_SetItemText($hListview, $Sel - 1, $SelItem[$i], $i - 1)
_GUICtrlListView_SetItemSelected($hListview, $Sel - 1)
Next
EndIf
_Arrange_Numbers()
EndFunc ;==>Move_Up

Func Move_Down()
Local $Sel, $Lst, $aArrayListView
$aArrayListView = _GUICtrlListView_CreateArray($hListview)
$Sel = _GUICtrlListView_GetNextItem($hListview)
$Lst = _GUICtrlListView_GetItemCount($hListview) - 1
If $Sel < $Lst And $Sel <> -1 Then
Local $SelItem, $NxtItem
$SelItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel)
$NxtItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel + 1)
For $i = 1 To $SelItem[0]
$aArrayListView[$Sel][$i - 1] = $NxtItem[$i]
$aArrayListView[$Sel + 1][$i - 1] = $SelItem[$i]
_GUICtrlListView_SetItemText($hListview, $Sel, $NxtItem[$i], $i - 1)
_GUICtrlListView_SetItemText($hListview, $Sel + 1, $SelItem[$i], $i - 1)
_GUICtrlListView_SetItemSelected($hListview, $Sel + 1)
Next
EndIf
_Arrange_Numbers()
EndFunc ;==>Move_Down

Func _GUICtrlListView_CreateArray($hListview, $sDelimeter = '|')
Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListview), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListview)
If $iColumnCount < 3 Then
$iDim = 3 - $iColumnCount
EndIf
If $sDelimeter = Default Then
$sDelimeter = '|'
EndIf
Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
For $i = 0 To $iColumnCount - 1
$aColumns = _GUICtrlListView_GetColumn($hListview, $i)
$aReturn[0][2] &= $aColumns[5] & $sDelimeter
Next
$aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))
For $i = 0 To $iItemCount - 1
For $j = 0 To $iColumnCount - 1
$aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListview, $i, $j)
Next
Next
Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc ;==>_GUICtrlListView_CreateArray

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
Local $aHit = _GUICtrlListView_SubItemHitTest($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)
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] + 3, $aRect[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)

Case $NM_RCLICK
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
If DllStructGetData($tInfo, "Item") > -1 Then
_GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

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 ;==>FrameRect

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
Local $iText = _GUICtrlEdit_GetText($hEdit)
_GUICtrlListView_SetItemText($hListview, $Item, $iText, $SubItem)
_WinAPI_DeleteObject($hBrush)
_WinAPI_ReleaseDC($hEdit, $hDC)
_WinAPI_DestroyWindow($hEdit)
$Item = -1
$SubItem = 0
EndSwitch
EndSwitch
Switch $wParam
Case $idMoveUp
Move_Up()
Case $idMoveDown
Move_Down()
Case $idDelete
Delete_Item()
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Edited by KaFu

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi KaFu,

Very Nice, thanks ;)

Sorry for this late answer, my fault.

Only a little problem, if i use:

$cListview = GUICtrlCreateListView("N°|Name|Subject", 5, 5, 250, 272, $LVS_REPORT)

The Move_Up and Move_Down function not work. Do you know why and if can be resolved?

Thanks again

EDIT: Oh, for center the Edit rect in the same position of the item, just change this line:

$hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + 8, $aRect[1] + 7, $iLen + 10, 17, $Style)
Edited by johnmcloud

Share this post


Link to post
Share on other sites

But if i use $LVS_SINGLESEL i can't select multiple items with CTRL or SHIFT, right? I'd like to make multiple selection ;)

Share this post


Link to post
Share on other sites

Yeah, that's right. I think the problem is not the LV style, but within the functions Move_Up and Move_Down.

You only select new ones, but you don't deselect the old ones, see this line.

_GUICtrlListView_SetItemSelected($hListview, $Sel, 0)

I guess you need to think of a way on how to handle the move operation when more than one item is selected, this scenario is currently not reflected in the functions.

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>

Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0, $Number = 0, $hMenu
Global Enum $idMoveUp = 1000, $idMoveDown, $idDelete
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)

$hGUI = GUICreate("_GUICtrlListView_Example", 262, 351, -1, -1)
;$cListview = GUICtrlCreateListView("N°|Name|Subject", 5, 5, 250, 272)
$cListview = GUICtrlCreateListView("N°|Name|Subject", 5, 5, 250, 272, $LVS_REPORT)
$hListview = GUICtrlGetHandle($cListview)

_GUICtrlListView_SetExtendedListViewStyle($hListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
_GUICtrlListView_SetColumnWidth($hListview, 0, 35)
_GUICtrlListView_SetColumnWidth($hListview, 1, 107)
_GUICtrlListView_SetColumnWidth($hListview, 2, 108)

$Label = GUICtrlCreateLabel("Name", 13, 290, 67, 17)
$c_Button_Add = GUICtrlCreateButton("Add", 90, 315, 80, 25)
$Info = GUICtrlCreateInput("Subject", 88, 286, 83, 21)
$c_Button_Save = GUICtrlCreateButton("Save", 174, 284, 80, 25)

$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Move Up", $idMoveUp)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Move Down", $idMoveDown)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "Delete", $idDelete)

$c_Dummy_Down = GUICtrlCreateDummy()
$c_Dummy_Up = GUICtrlCreateDummy()
$c_Dummy_Delete = GUICtrlCreateDummy()
$c_Dummy_Enter = GUICtrlCreateDummy()

Local $AccelKeys[4][2] = [["{DELETE}", $c_Dummy_Delete],["{UP}", $c_Dummy_Up],["{DOWN}", $c_Dummy_Down],["{ENTER}", $c_Dummy_Enter]]
GUISetAccelerators($AccelKeys, $hGUI)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListview)]

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $c_Button_Add
            Add_Item()
        Case $c_Button_Save
            Save_List()
        Case $c_Dummy_Delete
            Delete_Item()
        Case $c_Dummy_Down
            Move_Down()
        Case $c_Dummy_Up
            Move_Up()
        Case $c_Dummy_Enter
            If _WinAPI_GetFocus() = $hEdit Then _WinAPI_SetFocus($hListview) ; fires $EN_KILLFOCUS in WM_COMMAND
        Case $cListview
            _GUICtrlListView_SimpleSort($hListview, $B_DESCENDING, GUICtrlGetState($cListview))

    EndSwitch
WEnd

Func Add_Item()
    $Number += 1
    _GUICtrlListView_AddItem($hListview, $Number, -1, 9999 + $Number) ; add lparam value, is used for sorting as far as I remember
    _GUICtrlListView_AddSubItem($hListview, $Number - 1, GUICtrlRead($Label), 1)
    _GUICtrlListView_AddSubItem($hListview, $Number - 1, GUICtrlRead($Info), 2)
EndFunc   ;==>Add_Item

Func Delete_Item()
    _GUICtrlListView_DeleteItemsSelected($hListview)
    _Arrange_Numbers()
EndFunc   ;==>Delete_Item

Func _Arrange_Numbers()
    Dim $iCount = 0
    $Total_Number = _GUICtrlListView_GetItemCount($hListview) - 1
    For $i = 0 To $Total_Number
        $iCount += 1
        _GUICtrlListView_SetItemText($hListview, $i, $iCount)
    Next
EndFunc   ;==>_Arrange_Numbers

Func Save_List()
    Local $Save = FileSaveDialog("Save", @WorkingDir, "Txt Files (*.txt)", 2, "Test_File_" & @MDAY & "-" & @MON & "-" & @YEAR & "_" & @HOUR & "-" & @MIN)
    If @error Then
        ConsoleWrite("Abort")
    Else
        $List = FileOpen($Save & ".txt", 2)
        $Number_items = _GUICtrlListView_GetItemCount($hListview)
        For $i = 0 To $Number_items - 1 Step +1
            $output = StringReplace(_GUICtrlListView_GetItemTextString($hListview, $i), "|", " - ")
            FileWriteLine($List, $output)
        Next
        FileClose($List)
    EndIf
EndFunc   ;==>Save_List

Func Move_Up()
    Local $Sel, $aArrayListView
    $aArrayListView = _GUICtrlListView_CreateArray($hListview)
    $Sel = _GUICtrlListView_GetNextItem($hListview)
    If $Sel > 0 Then
        Local $SelItem, $NxtItem
        $SelItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel)
        $PrvItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel - 1)
        For $i = 1 To $SelItem[0]
            $aArrayListView[$Sel][$i - 1] = $PrvItem[$i]
            $aArrayListView[$Sel - 1][$i - 1] = $SelItem[$i]
            _GUICtrlListView_SetItemText($hListview, $Sel, $PrvItem[$i], $i - 1)
            _GUICtrlListView_SetItemText($hListview, $Sel - 1, $SelItem[$i], $i - 1)
            _GUICtrlListView_SetItemSelected($hListview, $Sel, 0)
            _GUICtrlListView_SetItemSelected($hListview, $Sel - 1)
        Next
    EndIf
    _Arrange_Numbers()
EndFunc   ;==>Move_Up

Func Move_Down()
    Local $Sel, $Lst, $aArrayListView
    $aArrayListView = _GUICtrlListView_CreateArray($hListview)
    $Sel = _GUICtrlListView_GetNextItem($hListview)
    $Lst = _GUICtrlListView_GetItemCount($hListview) - 1
    If $Sel < $Lst And $Sel <> -1 Then
        Local $SelItem, $NxtItem
        $SelItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel)
        $NxtItem = _GUICtrlListView_GetItemTextArray($hListview, $Sel + 1)
        For $i = 1 To $SelItem[0]
            $aArrayListView[$Sel][$i - 1] = $NxtItem[$i]
            $aArrayListView[$Sel + 1][$i - 1] = $SelItem[$i]
            _GUICtrlListView_SetItemText($hListview, $Sel, $NxtItem[$i], $i - 1)
            _GUICtrlListView_SetItemText($hListview, $Sel + 1, $SelItem[$i], $i - 1)
            _GUICtrlListView_SetItemSelected($hListview, $Sel, 0)
            _GUICtrlListView_SetItemSelected($hListview, $Sel + 1)
        Next
    EndIf
    _Arrange_Numbers()
EndFunc   ;==>Move_Down

Func _GUICtrlListView_CreateArray($hListview, $sDelimeter = '|')
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListview), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListview)
    If $iColumnCount < 3 Then
        $iDim = 3 - $iColumnCount
    EndIf
    If $sDelimeter = Default Then
        $sDelimeter = '|'
    EndIf
    Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
    For $i = 0 To $iColumnCount - 1
        $aColumns = _GUICtrlListView_GetColumn($hListview, $i)
        $aReturn[0][2] &= $aColumns[5] & $sDelimeter
    Next
    $aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))
    For $i = 0 To $iItemCount - 1
        For $j = 0 To $iColumnCount - 1
            $aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListview, $i, $j)
        Next
    Next
    Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc   ;==>_GUICtrlListView_CreateArray

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
                    Local $aHit = _GUICtrlListView_SubItemHitTest($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)
                    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] + 3, $aRect[1], $iLen + 10, 17, $Style)
                    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + 8, $aRect[1] + 7, $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)

                Case $NM_RCLICK
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    If DllStructGetData($tInfo, "Item") > -1 Then
                        _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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   ;==>FrameRect

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListview, $Item, $iText, $SubItem)
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch
    Switch $wParam
        Case $idMoveUp
            Move_Up()
        Case $idMoveDown
            Move_Down()
        Case $idDelete
            Delete_Item()
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Share this post


Link to post
Share on other sites

johnmcloud,

Take a look at my GUIListViewEx UDF. I faced the same problem (how to handle the move operation when more than one item is selected) and decided that I would only accept a consecutive block. There is some code in there (look at lines 829-860) which might help you do the same thing in your script. ;)

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

#9 ·  Posted (edited)

I have added the Melba's code part about the moving part:

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0, $Number = 0, $hMenu
Global Enum $idMoveUp = 1000, $idMoveDown, $idDelete
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hGUI = GUICreate("_GUICtrlListView_Example", 262, 351, -1, -1)
$cListview = GUICtrlCreateListView("N°|Name|Subject", 5, 5, 250, 272, $LVS_REPORT)
$hListview = GUICtrlGetHandle($cListview)
_GUICtrlListView_SetExtendedListViewStyle($hListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
_GUICtrlListView_SetColumnWidth($hListview, 0, 35)
_GUICtrlListView_SetColumnWidth($hListview, 1, 107)
_GUICtrlListView_SetColumnWidth($hListview, 2, 108)
$Label = GUICtrlCreateLabel("Name", 13, 290, 67, 17)
$c_Button_Add = GUICtrlCreateButton("Add", 90, 315, 80, 25)
$Info = GUICtrlCreateInput("Subject", 88, 286, 83, 21)
$c_Button_Save = GUICtrlCreateButton("Save", 174, 284, 80, 25)
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Move Up", $idMoveUp)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Move Down", $idMoveDown)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "Delete", $idDelete)
$c_Dummy_Down = GUICtrlCreateDummy()
$c_Dummy_Up = GUICtrlCreateDummy()
$c_Dummy_Delete = GUICtrlCreateDummy()
$c_Dummy_Enter = GUICtrlCreateDummy()
Local $AccelKeys[4][2] = [["{DELETE}", $c_Dummy_Delete],["{UP}", $c_Dummy_Up],["{DOWN}", $c_Dummy_Down],["{ENTER}", $c_Dummy_Enter]]
GUISetAccelerators($AccelKeys, $hGUI)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListview)]
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $c_Button_Add
Add_Item()
Case $c_Button_Save
Save_List()
Case $c_Dummy_Delete
Delete_Item()
Case $c_Dummy_Down
Move_Down()
Case $c_Dummy_Up
Move_Up()
Case $c_Dummy_Enter
If _WinAPI_GetFocus() = $hEdit Then _WinAPI_SetFocus($hListview) ; fires $EN_KILLFOCUS in WM_COMMAND
Case $cListview
_GUICtrlListView_SimpleSort($hListview, $B_DESCENDING, GUICtrlGetState($cListview))
EndSwitch
WEnd
Func Add_Item()
$Number += 1
_GUICtrlListView_AddItem($hListview, $Number, -1, 9999 + $Number) ; add lparam value, is used for sorting as far as I remember
_GUICtrlListView_AddSubItem($hListview, $Number - 1, GUICtrlRead($Label), 1)
_GUICtrlListView_AddSubItem($hListview, $Number - 1, GUICtrlRead($Info), 2)
EndFunc ;==>Add_Item
Func Delete_Item()
_GUICtrlListView_DeleteItemsSelected($hListview)
_Arrange_Numbers()
EndFunc ;==>Delete_Item
Func _Arrange_Numbers()
Dim $iCount = 0
$Total_Number = _GUICtrlListView_GetItemCount($hListview) - 1
For $i = 0 To $Total_Number
$iCount += 1
_GUICtrlListView_SetItemText($hListview, $i, $iCount)
Next
EndFunc ;==>_Arrange_Numbers
Func Save_List()
Local $Save = FileSaveDialog("Save", @WorkingDir, "Txt Files (*.txt)", 2, "Test_File_" & @MDAY & "-" & @MON & "-" & @YEAR & "_" & @HOUR & "-" & @MIN)
If @error Then
ConsoleWrite("Abort")
Else
$List = FileOpen($Save & ".txt", 2)
$Number_items = _GUICtrlListView_GetItemCount($hListview)
For $i = 0 To $Number_items - 1 Step +1
$output = StringReplace(_GUICtrlListView_GetItemTextString($hListview, $i), "|", " - ")
FileWriteLine($List, $output)
Next
FileClose($List)
EndIf
EndFunc ;==>Save_List
Func Move_Up()
; Get dragged item index
$iGLVExDragged_Index = DllStructGetData($tStruct, 4) ; Item
; Set dragged item count
$iGLVEx_Dragging = 1
; Check for selected items
Local $iIndex = _GUICtrlListView_GetSelectedIndices($hListview)
; Check if item is part of a multiple selection
If StringInStr($iIndex, $iGLVExDragged_Index) And StringInStr($iIndex, "|") Then
; Extract all selected items
Local $aIndex = StringSplit($iIndex, "|")
For $i = 1 To $aIndex[0]
If $aIndex[$i] = $iGLVExDragged_Index Then ExitLoop
Next
; Now check for consecutive items
If $i <> 1 Then ; Up
For $j = $i - 1 To 1 Step -1
; Consecutive?
If $aIndex[$j] <> $aIndex[$j + 1] - 1 Then ExitLoop
; Adjust dragged index to this item
$iGLVExDragged_Index -= 1
; Increase number to drag
$iGLVEx_Dragging += 1
Next
EndIf
If $i <> $aIndex[0] Then ; Down
For $j = $i + 1 To $aIndex[0]
; Consecutive
If $aIndex[$j] <> $aIndex[$j - 1] + 1 Then ExitLoop
; Increase number to drag
$iGLVEx_Dragging += 1
Next
EndIf
Else ; Either no selection or only a single
; Set flag
$iGLVEx_Dragging = 1
EndIf
_Arrange_Numbers()
EndFunc ;==>Move_Up
Func Move_Down()
;~ Test
EndFunc ;==>Move_Down
Func _GUICtrlListView_CreateArray($hListview, $sDelimeter = '|')
Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListview), $iDim = 0, $iItemCount = _GUICtrlListView_GetItemCount($hListview)
If $iColumnCount < 3 Then
$iDim = 3 - $iColumnCount
EndIf
If $sDelimeter = Default Then
$sDelimeter = '|'
EndIf
Local $aColumns = 0, $aReturn[$iItemCount + 1][$iColumnCount + $iDim] = [[$iItemCount, $iColumnCount, '']]
For $i = 0 To $iColumnCount - 1
$aColumns = _GUICtrlListView_GetColumn($hListview, $i)
$aReturn[0][2] &= $aColumns[5] & $sDelimeter
Next
$aReturn[0][2] = StringTrimRight($aReturn[0][2], StringLen($sDelimeter))
For $i = 0 To $iItemCount - 1
For $j = 0 To $iColumnCount - 1
$aReturn[$i + 1][$j] = _GUICtrlListView_GetItemText($hListview, $i, $j)
Next
Next
Return SetError(Number($aReturn[0][0] = 0), 0, $aReturn)
EndFunc ;==>_GUICtrlListView_CreateArray
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode
Global $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $ilParam)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListview
Switch $iCode
Case $NM_DBLCLK
     Local $aHit = _GUICtrlListView_SubItemHitTest($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)
     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] + 3, $aRect[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)
Case $NM_RCLICK
     $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
     If DllStructGetData($tInfo, "Item") > -1 Then
     _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI)
     EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
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 ;==>FrameRect
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
     Local $iText = _GUICtrlEdit_GetText($hEdit)
     _GUICtrlListView_SetItemText($hListview, $Item, $iText, $SubItem)
     _WinAPI_DeleteObject($hBrush)
     _WinAPI_ReleaseDC($hEdit, $hDC)
     _WinAPI_DestroyWindow($hEdit)
     $Item = -1
     $SubItem = 0
EndSwitch
EndSwitch
Switch $wParam
Case $idMoveUp
Move_Up()
Case $idMoveDown
Move_Down()
Case $idDelete
Delete_Item()
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND

Seemes do nothing and i don't have any error.

I'm sure is my mistake, or i don't have understand what i need to do with the flag :D

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • PINTO1927
      By PINTO1927
      Hi guys,
      through _GUICtrlListView GetItemText String formula you can only get the contents of a cell?
      example:
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $idListview GUICreate("ListView Get Item Text String", 400, 300) $idListview = GUICtrlCreateListView("col1|col2|col3", 2, 2, 394, 268) GUICtrlCreateListViewItem("line1|data1|more1", $idListview) GUICtrlCreateListViewItem("line2|data2|more2", $idListview) GUICtrlCreateListViewItem("line3|data3|more3", $idListview) GUICtrlCreateListViewItem("line4|data4|more4", $idListview) GUICtrlCreateListViewItem("line5|data5|more5", $idListview) GUISetState(@SW_SHOW) MsgBox($MB_SYSTEMMODAL, "Information", "Item 2 Text: " & @CRLF & @CRLF & _GUICtrlListView_GetItemTextString($idListview, 1)) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example In the MsgBox I would like to show only, for example, "data3", and not all the content of the line3.