Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/10/2023 in all areas

  1. Good catch 👍, I'm really baffled about the bad SendMessage results, and that GUICtrlSendMsg seems much faster, would have guessed the other way around. Must be related to GUICtrlSendMsg being a native function and the dllcall "workaround" creates additional overhead. KaFu_1_SendMessage = 49.8236 Nine = 9.794 KaFu_2_DllCallAddres = 24.0897 KaFu_3_GUICtrlSendMsg = 9.5192 Jpm = 599.1251 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <WinAPISys.au3> Example() Func Example() Local $idListview GUICreate("ListView Get Selected Indices", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT)) _GUICtrlListView_AddColumn($idListview, "Column 1", 100) For $i = 0 To 10000 _GUICtrlListView_AddItem($idListview, "Item " & $i) Next GUISetState(@SW_SHOW) For $i = 0 To 10000 Step 5 _GUICtrlListView_SetItemSelected($idListview, $i) Next Local $hTimer = TimerInit() Local $aList = _GUICtrlListView_GetSelectedIndices_KaFu_1(GUICtrlGetHandle($idListview)) ConsoleWrite("KaFu_1_SendMessage" & @TAB & @TAB & "= " & TimerDiff($hTimer) & @CRLF) ;_ArrayDisplay($aList) $hTimer = TimerInit() $aList = _GUICtrlListView_GetSelectedIndices9($idListview, True) ConsoleWrite("Nine" & @TAB & @TAB & @TAB & @TAB & "= " & TimerDiff($hTimer) & @CRLF) ;ConsoleWrite($aList & @CRLF) ; _ArrayDisplay($aList) Local $hTimer = TimerInit() Local $aList = _GUICtrlListView_GetSelectedIndices_KaFu_2(GUICtrlGetHandle($idListview)) ConsoleWrite("KaFu_2_DllCallAddress" & @TAB & @TAB & "= " & TimerDiff($hTimer) & @CRLF) ; _ArrayDisplay($aList) Local $hTimer = TimerInit() Local $aList = _GUICtrlListView_GetSelectedIndices_KaFu_3(GUICtrlGetHandle($idListview)) ConsoleWrite("KaFu_3_GUICtrlSendMsg" & @TAB & @TAB & "= " & TimerDiff($hTimer) & @CRLF) ; _ArrayDisplay($aList) $hTimer = TimerInit() $aList = _GUICtrlListView_GetSelectedIndices($idListview, True) ConsoleWrite("Jpm" & @TAB & @TAB & @TAB & @TAB & "= " & TimerDiff($hTimer) & @CRLF) ;ConsoleWrite($aList & @CRLF) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example Func _GUICtrlListView_GetSelectedIndices9($hWnd, $bArray = False) Local $iCount = _GUICtrlListView_GetSelectedCount($hWnd) Local $aSelect[$iCount + 1] = [$iCount] If Not $iCount Then Return $bArray ? $aSelect : "" Local $iIdx = -1, $sIndices If IsHWnd($hWnd) Then $hWnd = _WinAPI_GetDlgCtrlID($hWnd) For $i = 1 To $iCount $iIdx = GUICtrlSendMsg($hWnd, $LVM_GETNEXTITEM, $iIdx, $LVNI_SELECTED) If $bArray Then $aSelect[$i] = $iIdx Else $sIndices &= $iIdx & "|" EndIf Next Return $bArray ? $aSelect : StringTrimRight($sIndices, 1) EndFunc ;==>_GUICtrlListView_GetSelectedIndices9 Func _GUICtrlListView_GetSelectedIndices_KaFu_1($hWnd) Local $iSelectedCount = _GUICtrlListView_GetSelectedCount($hWnd) If $iSelectedCount Then Local $aIndices[$iSelectedCount + 1] $aIndices[0] = -1 ; -1 to find the first item that matches the specified flags (msdn) ; the specified item itself is excluded from the search (+++) For $i = 1 To $iSelectedCount $aIndices[$i] = _SendMessage($hWnd, $LVM_GETNEXTITEM, $aIndices[$i - 1], $LVNI_SELECTED) ; ConsoleWrite($i & @tab & $iEnum & @tab & $aIndices[0] & @crlf) Next $aIndices[0] = $iSelectedCount Else Local $aIndices[1] = [0] EndIf Return $aIndices EndFunc ;==>_GUICtrlListView_GetSelectedIndices_KaFu_1 Func _GUICtrlListView_GetSelectedIndices_KaFu_2($hWnd) Local $iCount = _GUICtrlListView_GetSelectedCount($hWnd) If $iCount Then Local $h_SendMessageW = _WinAPI_GetProcAddress(_WinAPI_GetModuleHandle("user32.dll"), "SendMessageW") Local $aSelect[$iCount + 1] $aSelect[0] = -1 ; -1 to find the first item that matches the specified flags (msdn) ; the specified item itself is excluded from the search (+++) For $i = 1 To $iCount $aSelect[$i] = DllCallAddress("int", $h_SendMessageW, "hwnd", $hWnd, "int", $LVM_GETNEXTITEM, "int", $aSelect[$i - 1], "int", $LVNI_SELECTED)[0] Next $aSelect[0] = $iCount Else Local $aSelect[1] = [0] EndIf Return $aSelect EndFunc ;==>_GUICtrlListView_GetSelectedIndices_KaFu_2 Func _GUICtrlListView_GetSelectedIndices_KaFu_3($hWnd) Local $iCount = _GUICtrlListView_GetSelectedCount($hWnd) If $iCount Then Local $aSelect[$iCount + 1] $aSelect[0] = -1 ; -1 to find the first item that matches the specified flags (msdn) ; the specified item itself is excluded from the search (+++) If IsHWnd($hWnd) Then $hWnd = _WinAPI_GetDlgCtrlID($hWnd) For $i = 1 To $iCount $aSelect[$i] = GUICtrlSendMsg($hWnd, $LVM_GETNEXTITEM, $aSelect[$i - 1], $LVNI_SELECTED) Next $aSelect[0] = $iCount Else Local $aSelect[1] = [0] EndIf Return $aSelect EndFunc ;==>_GUICtrlListView_GetSelectedIndices_KaFu_3
    2 points
  2. argumentum

    Active_SaveFileDlg

    Global $sIsOpenOrSave = "", $iCount = 0 While WinExists("[CLASS:SciTEWindow]") $hScite = WinGetHandle("[CLASS:SciTEWindow]") $hDlgWnd = ControlGetHandle ("[CLASS:#32770]", "", "ToolbarWindow323") If $hDlgWnd Then If ControlGetHandle( "[CLASS:#32770]", "", "ToolbarWindow325") Then $sIsOpenOrSave = "Save" Else $sIsOpenOrSave = "Open" EndIf $iCount = 0 ;;; https://www.autoitscript.com/forum/topic/210165-active_savefiledlg/?do=findComment&comment=1517896 While 1 $hDlgWnd = _WinAPI_GetParent($hDlgWnd) ;ConsoleWrite($hDlgWnd & @TAB & WinGetTitle($hDlgWnd) & @TAB & WinGetHandle("[CLASS:#32770]") & @CRLF) $iCount += 1 If $iCount = ( $sIsOpenOrSave = "Open" ? 6 : 4 ) Then ExitLoop WEnd _CallFoldersGUI($sIsOpenOrSave) EndIf Sleep(500) WEnd language is no longer important this way ..should check if the next parent is SciTE to make sure this code is not running on an unexpected window, but as is, is good enough to show the idea.
    2 points
  3. ioa747

    Txt split to ini file

    @mucitbey The fact that the combination doesn't show all the names has to do with _FileReadToArray Users.txt (which doesn't match well, check the Users.txt for the right format) as for Maradona, I registered it, it showed me normally, in the sample data I have, (username "2" comes from first row (0 index) of table "Users.txt" for 2 columns) I added 2 hotkeys to the script so you can check arrays HotKeySet("{HOME}", "aDataDisplay") ;Display the $aData Array HotKeySet("{END}", "aUsersDisplay") ;Display the $aUsers Array I also changed the function Func GetUserName($aUsers, $ID) ; ID to User Name ; https://www.autoitscript.com/forum/topic/210069-txt-split-to-ini-file/?do=findComment&comment=1517679 #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 ;-w 5 -w 6 -w 7 #include <Misc.au3> #include <File.au3> #include <Date.au3> #include <Array.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> _Singleton(@ScriptName, 0) Global $nMsg, $hGui, $idCombo, $lv, $CurUser Global $aUsers = WriteAllUserData() Global $aData = FindAllIniFile(@ScriptDir & "\Data\") AddAbsentUser() MakeMyGuiList() HotKeySet("{HOME}", "aDataDisplay") ;Display the $aData Array HotKeySet("{END}", "aUsersDisplay") ;Display the $aUsers Array While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $idCombo _GUICtrlComboBox_GetLBText($idCombo, _GUICtrlComboBox_GetCurSel($idCombo), $CurUser) UpDadeMyGuiList($CurUser) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd ;---------------------------------------------------------------------------------------- Func WriteAllUserData() ; Make all ini files Local $aDatalar, $aUsers, $UserName, $aTemp, $IniFile, $aSpl, $sDate _FileReadToArray("Datalar.txt", $aDatalar, $FRTA_NOCOUNT) _FileReadToArray("Users.txt", $aUsers, $FRTA_COUNT, "=") Local $iLines = UBound($aDatalar) $sDate = '' For $i = 0 To $iLines - 1 $aTemp = StringSplit($aDatalar[$i], ", ", $STR_NOCOUNT) $UserName = GetUserName($aUsers, $aTemp[1]) ; if no user skip If $UserName <> "" Then If $sDate <> $aTemp[3] Then $sDate = $aTemp[3] ;~ ; format date 00.00.0000 for ini FileName ;~ $aSpl = StringSplit($sDate, ".") ;~ If StringLen($aSpl[1]) = 1 Then $aSpl[1] = "0" & $aSpl[1] ;~ $IniFile = $aSpl[1] & "." & $aSpl[2] & "." & $aSpl[3] & ".ini" $IniFile = $sDate & ".ini" ;write ini If IniRead(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value01", "Non-existing key") = "Non-existing key" Then IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value01", $aTemp[1]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value02", $aTemp[3]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value03", $aTemp[4]) Else If IniRead(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value03", "<UNKNOWN>") <> $aTemp[4] Then IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value04", $aTemp[4]) EndIf EndIf EndIf Next Return $aUsers EndFunc ;==>WriteAllUserData ;---------------------------------------------------------------------------------------- Func GetUserName($aUsers, $ID) ; ID to User Name Local $sName For $i = 1 To $aUsers[0][0] $sName = "" If $aUsers[$i][0] = $ID Then $sName = $aUsers[$i][1] ExitLoop EndIf Next Return $sName EndFunc ;==>GetUserName ;---------------------------------------------------------------------------------------- Func FindAllIniFile($sStartPath = "") ; Find All Ini File If $sStartPath = "" Then $sStartPath = @ScriptDir Local $aArray[1][8] $aArray[0][0] = 0 ; "index" $aArray[0][1] = "UserID" $aArray[0][2] = "UserName" $aArray[0][3] = "Date" $aArray[0][4] = "Start" $aArray[0][5] = "End" $aArray[0][6] = "Time" $aArray[0][7] = "idItem" Local $ArraySrtfiles = _FileListToArrayRec($sStartPath, "*.ini", $FLTAR_FILES, $FLTAR_RECUR) If Not IsArray($ArraySrtfiles) Then ConsoleWrite($sStartPath & " = Invalid input path" & @CRLF) Return Else For $x = 1 To $ArraySrtfiles[0] ;ConsoleWrite($sStartPath & $ArraySrtfiles[$x]& @CRLF) ReadIniToArray($aArray, $sStartPath & $ArraySrtfiles[$x]) Next Return $aArray EndIf EndFunc ;==>FindAllIniFile ;---------------------------------------------------------------------------------------- Func ReadIniToArray(ByRef $aArray, $TxtFile) ; Read Ini To Array Local $index ;Read the INI section names. This will return a 1 dimensional array. Local $aSections = IniReadSectionNames($TxtFile) ;Check if an error occurred. If Not @error Then ;Enumerate through the array displaying the section names. For $i = 1 To $aSections[0] ReDim $aArray[UBound($aArray) + 1][8] $aArray[0][0] += 1 $index = $aArray[0][0] $aArray[$index][0] = $index ;"index" $aArray[$index][1] = IniRead($TxtFile, $aSections[$i], "Value01", "Null") ;"UserID" $aArray[$index][2] = $aSections[$i] ;"UserName" $aArray[$index][3] = IniRead($TxtFile, $aSections[$i], "Value02", "Null") ;"Date" $aArray[$index][4] = IniRead($TxtFile, $aSections[$i], "Value03", "Null") ;"Start" $aArray[$index][5] = IniRead($TxtFile, $aSections[$i], "Value04", "Null") ;"End" $aArray[$index][6] = "" ;"Time" Next EndIf EndFunc ;==>ReadIniToArray ;---------------------------------------------------------------------------------------- Func MakeMyGuiList() ; GUI Create $hGui = GUICreate("_ank_ File Splitting", 510, 560, -1, -1) $lv = GUICtrlCreateListView("CART ID |DATE |START |END |TIME|NAME AND SURNAME", 10, 30, 490, 520) Local $sLine For $i = 1 To $aData[0][0] $sLine = $aData[$i][1] & "|" & $aData[$i][3] & "|" & $aData[$i][4] & "|" $sLine &= $aData[$i][5] & "|" & TimeDiff($aData[$i][4], $aData[$i][5]) & "|" & $aData[$i][2] $aData[$i][7] = GUICtrlCreateListViewItem($sLine, $lv) If $aData[$i][4] > "08:10:00" And $aData[$i][4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][5] > "08:10:00" And $aData[$i][5] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][4] = "Null" Or $aData[$i][5] = "Null" Then GUICtrlSetBkColor(-1, 0xFFE5FF) Next $idCombo = GUICtrlCreateCombo("Select User", 10, 1, 490, 25) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") For $i = 1 To $aUsers[0][0] _GUICtrlComboBox_AddString($idCombo, $aUsers[$i][1]) Next GUISetState(@SW_SHOW) EndFunc ;==>MakeMyGuiList ;---------------------------------------------------------------------------------------- Func UpDadeMyGuiList($Filter) ; delete items Local $hlv = GUICtrlGetHandle($lv) _GUICtrlListView_DeleteAllItems($hlv) Local $sLine ; ReMake items For $i = 1 To $aData[0][0] If $Filter = "Select User" Then $sLine = $aData[$i][1] & "|" & $aData[$i][3] & "|" & $aData[$i][4] & "|" $sLine &= $aData[$i][5] & "|" & TimeDiff($aData[$i][4], $aData[$i][5]) & "|" & $aData[$i][2] $aData[$i][7] = GUICtrlCreateListViewItem($sLine, $lv) If $aData[$i][4] > "08:10:00" And $aData[$i][4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][5] > "08:10:00" And $aData[$i][5] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][4] = "Null" Or $aData[$i][5] = "Null" Then GUICtrlSetBkColor(-1, 0xFFE5FF) ContinueLoop Else If $aData[$i][2] = $Filter Then $sLine = $aData[$i][1] & "|" & $aData[$i][3] & "|" & $aData[$i][4] & "|" $sLine &= $aData[$i][5] & "|" & TimeDiff($aData[$i][4], $aData[$i][5]) & "|" & $aData[$i][2] $aData[$i][7] = GUICtrlCreateListViewItem($sLine, $lv) If $aData[$i][4] > "08:10:00" And $aData[$i][4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][5] > "08:10:00" And $aData[$i][5] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][4] = "Null" Or $aData[$i][5] = "Null" Then GUICtrlSetBkColor(-1, 0xFFE5FF) Else $aData[$i][7] = "" EndIf EndIf Next EndFunc ;==>UpDadeMyGuiList ;---------------------------------------------------------------------------------------- Func AddAbsentUser() Local $sLine, $IniFile, $aSpl, $aArray = $aData ;*[Add Absent User to $aData Array Local $aDateUnique = _ArrayUnique($aArray, 3, 1) For $d = 1 To $aDateUnique[0] For $i = 1 To $aUsers[0][0] If _GetThis($aUsers[$i][0] & "-" & $aDateUnique[$d]) = -1 Then $aData[0][0] += 1 $sLine = $aData[0][0] & "|" & $aUsers[$i][0] & "|" & $aUsers[$i][1] & "|" & $aDateUnique[$d] & "|Null|Null" _ArrayAdd($aData, $sLine) EndIf Next Next ;Add Absent User to $aData Array]* ;*[proper Array Sort order For $i = 1 To $aData[0][0] ; format date YYYY.MM.DD.HH.MM.SS $aSpl = StringSplit($aData[$i][3], ".") If StringLen($aSpl[1]) = 1 Then $aSpl[1] = "0" & $aSpl[1] $sLine = $aSpl[3] & "." & $aSpl[2] & "." & $aSpl[1] & "." & $aData[$i][4] $aData[$i][0] = $sLine Next _ArraySort($aData, 0, 1) For $i = 1 To $aData[0][0] $aData[$i][0] = $i Next ;proper Array Sort order]* ;*[Write $aData Array to ini For $i = 1 To $aData[0][0] ;~ ; format date 00.00.0000 for ini FileName ;~ $aSpl = StringSplit($aData[$i][3], ".") ;~ If StringLen($aSpl[1]) = 1 Then $aSpl[1] = "0" & $aSpl[1] ;~ $IniFile = $aSpl[1] & "." & $aSpl[2] & "." & $aSpl[3] & ".ini" $IniFile = $aData[$i][3] & ".ini" ;write ini IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value01", $aData[$i][1]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value02", $aData[$i][3]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value03", $aData[$i][4]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value04", $aData[$i][5]) Next ;Write $aData Array to ini]* EndFunc ;==>AddAbsentUser ;---------------------------------------------------------------------------------------- Func _GetThis($Txt) Local $sIndex For $i = 1 To $aData[0][0] $sIndex = -1 If $aData[$i][1] & "-" & $aData[$i][3] = $Txt Then $sIndex = $i ExitLoop EndIf Next Return $sIndex EndFunc ;==>_GetThis ;---------------------------------------------------------------------------------------- Func TimeDiff($sStartTime, $sEndTime) Local $H, $M, $sDiff, $aSpl1, $aSpl2 $aSpl1 = StringSplit($sStartTime, ":") $aSpl2 = StringSplit($sEndTime, ":") If $aSpl1[0] + $aSpl2[0] <> 6 Then ;ConsoleWrite("! Error No valid time format" & @CRLF) Return SetError(1, 0, "") EndIf ; ** 2020/01/01 ** since all the results are from the same date $M = _DateDiff('n', "2020/01/01 " & $sStartTime, "2020/01/01 " & $sEndTime) $H = Floor($M / 60) $M = Mod($M, 60) $sDiff = StringFormat("%i:%02i", $H, $M) Return $sDiff EndFunc ;==>TimeDiff ;---------------------------------------------------------------------------------------- Func aDataDisplay() _ArrayDisplay($aData, "$aData") EndFunc ;==>MyArrayDisplay ;---------------------------------------------------------------------------------------- Func aUsersDisplay() _ArrayDisplay($aUsers, "$aUsers") EndFunc
    1 point
  4. Here my take on it (seems SendMessage is slower) : #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $idListview GUICreate("ListView Get Selected Indices", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT)) _GUICtrlListView_AddColumn($idListview, "Column 1", 100) For $i = 0 To 10000 _GUICtrlListView_AddItem($idListview, "Item " & $i) Next GUISetState(@SW_SHOW) For $i = 0 To 10000 Step 5 _GUICtrlListView_SetItemSelected($idListview, $i) Next Local $hTimer = TimerInit() Local $aList = _GUICtrlListView_GetSelectedIndices_KAF(GUICtrlGetHandle($idListview)) ConsoleWrite("Kafu = " & TimerDiff($hTimer) & @CRLF) ;_ArrayDisplay($aList) $hTimer = TimerInit() $aList = _GUICtrlListView_GetSelectedIndices9($idListview, True) ConsoleWrite("Nine = " & TimerDiff($hTimer) & @CRLF) ;ConsoleWrite($aList & @CRLF) ;_ArrayDisplay($aList) $hTimer = TimerInit() $aList = _GUICtrlListView_GetSelectedIndices($idListview, True) ConsoleWrite("Jpm = " & TimerDiff($hTimer) & @CRLF) ;ConsoleWrite($aList & @CRLF) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example Func _GUICtrlListView_GetSelectedIndices9($hWnd, $bArray = False) Local $iCount = _GUICtrlListView_GetSelectedCount($hWnd) Local $aSelect[$iCount + 1] = [$iCount] If Not $iCount Then Return $bArray ? $aSelect : "" Local $iIdx = -1, $sIndices If IsHWnd($hWnd) Then $hWnd = _WinAPI_GetDlgCtrlID($hWnd) For $i = 1 To $iCount $iIdx = GUICtrlSendMsg($hWnd, $LVM_GETNEXTITEM, $iIdx, $LVNI_SELECTED) If $bArray Then $aSelect[$i] = $iIdx Else $sIndices &= $iIdx & "|" EndIf Next Return $bArray ? $aSelect : StringTrimRight($sIndices, 1) EndFunc ;==>_GUICtrlListView_GetSelectedIndices9 Func _GUICtrlListView_GetSelectedIndices_KAF($hWnd) Local $iSelectedCount = _GUICtrlListView_GetSelectedCount($hWnd) If $iSelectedCount Then Local $aIndices[$iSelectedCount + 1] $aIndices[0] = -1 ; -1 to find the first item that matches the specified flags (msdn) ; the specified item itself is excluded from the search (+++) For $i = 1 To $iSelectedCount $aIndices[$i] = _SendMessage($hWnd, $LVM_GETNEXTITEM, $aIndices[$i - 1], $LVNI_SELECTED) ; ConsoleWrite($i & @tab & $iEnum & @tab & $aIndices[0] & @crlf) Next $aIndices[0] = $iSelectedCount Else Local $aIndices[1] = [0] EndIf Return $aIndices EndFunc ;==>_GUICtrlListView_GetSelectedIndices_KAF Results with array : Kafu = 23.2122 Nine = 4.895 Jpm = 296.4108 Results with string : Nine = 4.6947 Jpm = 6.2971
    1 point
  5. #pixelsearch I did as you said, the result is as you said. Good luck with your spirit. It's nice that #ioa747 shows the check-in time and check-out time in the same column. I like this look a little more. Is it possible to change the time(input) time(output) in the listview for this script of yours?
    1 point
  6. @KaFu Since we already know the selected count with _GUICtrlListView_GetSelectedCount. Why not create the array with the exact size at first ?
    1 point
  7. Added children flag on all items after search. New version available.
    1 point
  8. @mucitbey Please try the script below to see if it does what is expected, with the corresponding Users.txt and Datalar.txt found below. Just place the 3 files in a new folder and run the script, it should display the same listview as in the pic below. In this example, Gisele Bündchen is absent on 12.04.2023 , Candice Swanepoel is absent on 13.04.2023 , an unknown ID 999 checked on 13.04.2023 (red background). The lines with blue background got the usual meaning (user checked after 8h10 and before 17h00). A blank line separates each new day in the listview. Please have a look at the 2 daily ini files created in the new folder, everything seems to be correct. Good luck #include <File.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Global $aData, $aUser, $aUser_Backup _FileReadToArray(@ScriptDir & "\" & "Datalar.txt", $aData, $FRTA_NOCOUNT) ; 1D array If @error Then Exit MsgBox($MB_TOPMOST, "_FileReadToArray error = " & @error, "Datalar.txt") $iLinesData = UBound($aData) _FileReadToArray(@ScriptDir & "\" & "Users.txt", $aUser, $FRTA_NOCOUNT, "=") ; 2D array If @error Then Exit MsgBox($MB_TOPMOST, "_FileReadToArray error = " & @error, "Users.txt") $iLinesUser = UBound($aUser) ReDim $aUser[$iLinesUser][3] ; add one empty column 2 at the right (to remember users who were present daily) $aUser_Backup = $aUser ; keep a copy with last column 2 empty for all users. Reuse this backup when date changes. $hTemplate = FileOpen(@ScriptDir & "\" & "Users template.ini", $FO_OVERWRITE + $FO_UNICODE) ; $FO_ANSI also worked. If $hTemplate = -1 Then Exit MsgBox($MB_TOPMOST, "FileOpen error", "Users template.ini") For $i = 0 To $iLinesUser - 1 FileWriteLine($hTemplate, _ "[" & $aUser[$i][1] & "]" & @crlf & _ "Value01=" & $aUser[$i][0] & @crlf & _ "Value02=" & @crlf & "Value03=" & @crlf & "Value04=" & @crlf) Next FileClose($hTemplate) GUICreate("_ank_ File Splitting", 430, 500, -1, -1) $lv = GUICtrlCreateListView("CART ID |DATE |TIME-1 |NAME AND SURNAME ", 10, 10, 410, 480) $sDate = '' For $li = 0 To $iLinesData - 1 $aTemp = StringSplit(StringStripWS($aData[$li], 1+2), ", ", $STR_NOCOUNT) ; strip leading (1) and trailing (2) eventual white space If @error Then ContinueLoop ; eliminate accidental blank lines. Help file StringSplit: "@error = 1 when no delimiters were found" If $sDate <> $aTemp[3] Then ; $sDate is the old date, $aTemp[3] is the new date. If $sDate Then ; always False when $li = 0 (first data line processed) Add_Absents($sDate) ; add eventual absents AFTER a day has been processed. $aUser = $aUser_Backup ; blank column 2 in $aUser, for all users, when the date changes. GUICtrlCreateListViewItem("", $lv) ; 1 empty line between each day processed (sort of vertical separator) EndIf $sIniFile = @ScriptDir & "\" & $aTemp[3] & ".ini" $iRet = FileCopy(@ScriptDir & "\" & "Users template.ini", $sIniFile, $FC_OVERWRITE) ; date changes => new ini file (based on ini template) If $iRet = 0 Then Exit MsgBox($MB_TOPMOST, "FileCopy error", $sIniFile) ; maybe existed read-only => overwrite fails $sDate = $aTemp[3] ; old date = new date EndIf $user = GetUser($aTemp[1]) ; user name GUICtrlCreateListViewItem($aTemp[1] &"|"& $aTemp[3] &"|"& $aTemp[4] &"|"& $user, $lv) If $aTemp[4] > "08:10:00" And $aTemp[4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) ; light blue If $user = "Undefined ID" Then $user = $aTemp[1] ; user name becomes ID (this should never happen, according to mucitbey) GUICtrlSetBkColor(-1, 0xFF0000) ; red EndIf $sKey = IniRead($sIniFile, $user, "Value03", "Undefined ID") ; remember Value03 = in-time ; $sKey has 3 possible values : ; 1) "" means we need to update "Value03" (1st entry for this user in Datalar.txt for this day) ; 2) "07:01:00" (for example) means we need to update "Value04" (2nd entry for this user in Datalar.txt for this day) ; 3) "Undefined ID" means... what it says (sabotage in Users.txt) then we add a new section in daily ini file, based on ID Select Case $sKey = "" IniWrite($sIniFile, $user, "Value02", $aTemp[3]) ; date IniWrite($sIniFile, $user, "Value03", $aTemp[4]) ; in-time Case StringRegExp($sKey, '\d\d:\d\d:\d\d') ; ex. '07:01:00' IniWrite($sIniFile, $user, "Value02", $aTemp[3]) ; date IniWrite($sIniFile, $user, "Value04", $aTemp[4]) ; out-time Case Else ; $sKey = "Undefined ID" IniWrite($sIniFile, $aTemp[1], "Value01", "Undefined ID") IniWrite($sIniFile, $aTemp[1], "Value02", $sDate) ; date IniWrite($sIniFile, $aTemp[1], "Value03", $aTemp[4]) ; in-time IniWrite($sIniFile, $aTemp[1], "Value04", "") ; out-time EndSelect Next If $sDate Then Add_Absents($sDate) ; add eventual absents for the last day processed. GUISetState(@SW_SHOW) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func GetUser($ID) For $iIndex = 0 To $iLinesUser - 1 If $aUser[$iIndex][0] = $ID Then ExitLoop Next If $iIndex < $iLinesUser Then ; user ID found in $aUser (e.g "Users.txt") $aUser[$iIndex][2] = 1 ; user worked that day. Column 2 will be blanked by reusing $aUser_Backup when date changes. Return $aUser[$iIndex][1] ; user name Else ; user ID not found in "Users.txt" (this can't happen, according to mucitbey) Return "Undefined ID" ; do not change this line (+++) EndIf EndFunc Func Add_Absents($sDate) For $i = 0 To $iLinesUser - 1 If Not $aUser[$i][2] Then ; user was absent that day ; add 1 line in ListView for the absent user (with a blank time) GUICtrlCreateListViewItem($aUser[$i][0] &"|"& $sDate &"|"& "" &"|"& $aUser[$i][1], $lv) ; update 1 line in ini file for the absent user (update the date line, e.g. Value02) IniWrite($sIniFile, $aUser[$i][1], "Value02", $sDate) ; date EndIf Next EndFunc Users.txt 00000001=Adriana Francesca Lima 00000010=Candice Swanepoel 00000017=Gisele Bündchen 00000020=Kendall Jenner Datalar.txt 001,00000001,00,12.04.2023 07:01:00 001,00000010,00,12.04.2023 07:10:00 001,00000001,00,12.04.2023 16:01:00 001,00000010,00,12.04.2023 16:10:00 001,00000020,00,12.04.2023 19:20:00 001,00000020,00,13.04.2023 06:20:00 001,00000999,00,13.04.2023 06:59:00 001,00000001,00,13.04.2023 07:01:00 001,00000017,00,13.04.2023 07:17:00 001,00000001,00,13.04.2023 16:01:00 001,00000017,00,13.04.2023 16:17:00
    1 point
  9. ioa747

    Txt split to ini file

    I also adapted the extended version ; https://www.autoitscript.com/forum/topic/210069-txt-split-to-ini-file/?do=findComment&comment=1517679 #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 ;-w 5 -w 6 -w 7 #include <Misc.au3> #include <File.au3> #include <Date.au3> #include <Array.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> _Singleton(@ScriptName, 0) Global $nMsg, $hGui, $idCombo, $lv, $CurUser Global $aUsers = WriteAllUserData() Global $aData = FindAllIniFile(@ScriptDir & "\Data\") AddAbsentUser() MakeMyGuiList() HotKeySet("{HOME}", "MyArrayDisplay") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $idCombo _GUICtrlComboBox_GetLBText($idCombo, _GUICtrlComboBox_GetCurSel($idCombo), $CurUser) UpDadeMyGuiList($CurUser) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd ;---------------------------------------------------------------------------------------- Func WriteAllUserData() ; Make all ini files Local $aDatalar, $aUsers, $UserName, $aTemp, $IniFile, $aSpl, $sDate _FileReadToArray("Datalar.txt", $aDatalar, $FRTA_NOCOUNT) _FileReadToArray("Users.txt", $aUsers, $FRTA_COUNT, "=") Local $iLines = UBound($aDatalar) $sDate = '' For $i = 0 To $iLines - 1 $aTemp = StringSplit($aDatalar[$i], ", ", $STR_NOCOUNT) $UserName = GetUserName($aUsers, $aTemp[1]) ; if no user skip If $UserName <> "" Then If $sDate <> $aTemp[3] Then $sDate = $aTemp[3] ;~ ; format date 00.00.0000 for ini FileName ;~ $aSpl = StringSplit($sDate, ".") ;~ If StringLen($aSpl[1]) = 1 Then $aSpl[1] = "0" & $aSpl[1] ;~ $IniFile = $aSpl[1] & "." & $aSpl[2] & "." & $aSpl[3] & ".ini" $IniFile = $sDate & ".ini" ;write ini If IniRead(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value01", "Non-existing key") = "Non-existing key" Then IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value01", $aTemp[1]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value02", $aTemp[3]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value03", $aTemp[4]) Else If IniRead(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value03", "<UNKNOWN>") <> $aTemp[4] Then IniWrite(@ScriptDir & "\Data\" & $IniFile, $UserName, "Value04", $aTemp[4]) EndIf EndIf EndIf Next Return $aUsers EndFunc ;==>WriteAllUserData ;---------------------------------------------------------------------------------------- Func GetUserName($aUsers, $ID) ; ID to User Name Local $iIndex = _ArraySearch($aUsers, $ID) If $iIndex <> -1 Then Return StringStripWS($aUsers[$iIndex][1], $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) Else Return "" EndIf EndFunc ;==>GetUserName ;---------------------------------------------------------------------------------------- Func FindAllIniFile($sStartPath = "") ; Find All Ini File If $sStartPath = "" Then $sStartPath = @ScriptDir Local $aArray[1][8] $aArray[0][0] = 0 ; "index" $aArray[0][1] = "UserID" $aArray[0][2] = "UserName" $aArray[0][3] = "Date" $aArray[0][4] = "Start" $aArray[0][5] = "End" $aArray[0][6] = "Time" $aArray[0][7] = "idItem" Local $ArraySrtfiles = _FileListToArrayRec($sStartPath, "*.ini", $FLTAR_FILES, $FLTAR_RECUR) If Not IsArray($ArraySrtfiles) Then ConsoleWrite($sStartPath & " = Invalid input path" & @CRLF) Return Else For $x = 1 To $ArraySrtfiles[0] ;ConsoleWrite($sStartPath & $ArraySrtfiles[$x]& @CRLF) ReadIniToArray($aArray, $sStartPath & $ArraySrtfiles[$x]) Next Return $aArray EndIf EndFunc ;==>FindAllIniFile ;---------------------------------------------------------------------------------------- Func ReadIniToArray(ByRef $aArray, $TxtFile) ; Read Ini To Array Local $index ;Read the INI section names. This will return a 1 dimensional array. Local $aSections = IniReadSectionNames($TxtFile) ;Check if an error occurred. If Not @error Then ;Enumerate through the array displaying the section names. For $i = 1 To $aSections[0] ReDim $aArray[UBound($aArray) + 1][8] $aArray[0][0] += 1 $index = $aArray[0][0] $aArray[$index][0] = $index ;"index" $aArray[$index][1] = IniRead($TxtFile, $aSections[$i], "Value01", "Null") ;"UserID" $aArray[$index][2] = $aSections[$i] ;"UserName" $aArray[$index][3] = IniRead($TxtFile, $aSections[$i], "Value02", "Null") ;"Date" $aArray[$index][4] = IniRead($TxtFile, $aSections[$i], "Value03", "Null") ;"Start" $aArray[$index][5] = IniRead($TxtFile, $aSections[$i], "Value04", "Null") ;"End" $aArray[$index][6] = "" ;"Time" Next EndIf EndFunc ;==>ReadIniToArray ;---------------------------------------------------------------------------------------- Func MakeMyGuiList() ; GUI Create $hGui = GUICreate("_ank_ File Splitting", 510, 560, -1, -1) $lv = GUICtrlCreateListView("CART ID |DATE |START |END |TIME|NAME AND SURNAME", 10, 30, 490, 520) Local $sLine For $i = 1 To $aData[0][0] $sLine = $aData[$i][1] & "|" & $aData[$i][3] & "|" & $aData[$i][4] & "|" $sLine &= $aData[$i][5] & "|" & TimeDiff($aData[$i][4], $aData[$i][5]) & "|" & $aData[$i][2] $aData[$i][7] = GUICtrlCreateListViewItem($sLine, $lv) If $aData[$i][4] > "08:10:00" And $aData[$i][4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][5] > "08:10:00" And $aData[$i][5] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][4] = "Null" Or $aData[$i][5] = "Null" Then GUICtrlSetBkColor(-1, 0xFFE5FF) Next $idCombo = GUICtrlCreateCombo("Select User", 10, 1, 490, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") For $i = 1 To $aUsers[0][0] _GUICtrlComboBox_AddString($idCombo, $aUsers[$i][1]) Next GUISetState(@SW_SHOW) EndFunc ;==>MakeMyGuiList ;---------------------------------------------------------------------------------------- Func UpDadeMyGuiList($Filter) ; delete items Local $hlv = GUICtrlGetHandle($lv) _GUICtrlListView_DeleteAllItems($hlv) Local $sLine ; ReMake items For $i = 1 To $aData[0][0] If $Filter = "Select User" Then $sLine = $aData[$i][1] & "|" & $aData[$i][3] & "|" & $aData[$i][4] & "|" $sLine &= $aData[$i][5] & "|" & TimeDiff($aData[$i][4], $aData[$i][5]) & "|" & $aData[$i][2] $aData[$i][7] = GUICtrlCreateListViewItem($sLine, $lv) If $aData[$i][4] > "08:10:00" And $aData[$i][4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][5] > "08:10:00" And $aData[$i][5] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][4] = "Null" Or $aData[$i][5] = "Null" Then GUICtrlSetBkColor(-1, 0xFFE5FF) ContinueLoop Else If $aData[$i][2] = $Filter Then $sLine = $aData[$i][1] & "|" & $aData[$i][3] & "|" & $aData[$i][4] & "|" $sLine &= $aData[$i][5] & "|" & TimeDiff($aData[$i][4], $aData[$i][5]) & "|" & $aData[$i][2] $aData[$i][7] = GUICtrlCreateListViewItem($sLine, $lv) If $aData[$i][4] > "08:10:00" And $aData[$i][4] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][5] > "08:10:00" And $aData[$i][5] < "17:00:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF) If $aData[$i][4] = "Null" Or $aData[$i][5] = "Null" Then GUICtrlSetBkColor(-1, 0xFFE5FF) Else $aData[$i][7] = "" EndIf EndIf Next EndFunc ;==>UpDadeMyGuiList ;---------------------------------------------------------------------------------------- Func AddAbsentUser() Local $sLine, $IniFile, $aSpl, $aArray = $aData ;*[Add Absent User to $aData Array Local $aDateUnique = _ArrayUnique($aArray, 3, 1) For $d = 1 To $aDateUnique[0] For $i = 1 To $aUsers[0][0] If _GetThis($aUsers[$i][0] & "-" & $aDateUnique[$d]) = -1 Then $aData[0][0] += 1 $sLine = $aData[0][0] & "|" & $aUsers[$i][0] & "|" & $aUsers[$i][1] & "|" & $aDateUnique[$d] & "|Null|Null" _ArrayAdd($aData, $sLine) EndIf Next Next ;Add Absent User to $aData Array]* ;*[proper Array Sort order For $i = 1 To $aData[0][0] ; format date YYYY.MM.DD.HH.MM.SS $aSpl = StringSplit($aData[$i][3], ".") If StringLen($aSpl[1]) = 1 Then $aSpl[1] = "0" & $aSpl[1] $sLine = $aSpl[3] & "." & $aSpl[2] & "." & $aSpl[1] & "." & $aData[$i][4] $aData[$i][0] = $sLine Next _ArraySort($aData, 0, 1) For $i = 1 To $aData[0][0] $aData[$i][0] = $i Next ;proper Array Sort order]* ;*[Write $aData Array to ini For $i = 1 To $aData[0][0] ;~ ; format date 00.00.0000 for ini FileName ;~ $aSpl = StringSplit($aData[$i][3], ".") ;~ If StringLen($aSpl[1]) = 1 Then $aSpl[1] = "0" & $aSpl[1] ;~ $IniFile = $aSpl[1] & "." & $aSpl[2] & "." & $aSpl[3] & ".ini" $IniFile = $aData[$i][3] & ".ini" ;write ini IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value01", $aData[$i][1]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value02", $aData[$i][3]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value03", $aData[$i][4]) IniWrite(@ScriptDir & "\Data\" & $IniFile, $aData[$i][2], "Value04", $aData[$i][5]) Next ;Write $aData Array to ini]* EndFunc ;==>AddAbsentUser ;---------------------------------------------------------------------------------------- Func _GetThis($Txt) Local $sIndex For $i = 1 To $aData[0][0] $sIndex = -1 If $aData[$i][1] & "-" & $aData[$i][3] = $Txt Then $sIndex = $i ExitLoop EndIf Next Return $sIndex EndFunc ;==>_GetThis ;---------------------------------------------------------------------------------------- Func TimeDiff($sStartTime, $sEndTime) Local $H, $M, $sDiff, $aSpl1, $aSpl2 $aSpl1 = StringSplit($sStartTime, ":") $aSpl2 = StringSplit($sEndTime, ":") If $aSpl1[0] + $aSpl2[0] <> 6 Then ;ConsoleWrite("! Error No valid time format" & @CRLF) Return SetError(1, 0, "") EndIf ; ** 2020/01/01 ** since all the results are from the same date $M = _DateDiff('n', "2020/01/01 " & $sStartTime, "2020/01/01 " & $sEndTime) $H = Floor($M / 60) $M = Mod($M, 60) $sDiff = StringFormat("%i:%02i", $H, $M) Return $sDiff EndFunc ;==>TimeDiff ;---------------------------------------------------------------------------------------- Func MyArrayDisplay() _ArrayDisplay($aData, "$aData") EndFunc ;==>MyArrayDisplay ;----------------------------------------------------------------------------------------
    1 point
  10. Finally found the bug. Here's the fix, if you're interested and running from source. In _display_selection_rect, make this change: ;~ If GUICtrlGetHandle($overlay) <> -1 Then If $overlay <> -1 Then
    1 point
  11. Which browser ? Did you try with WD UDF ?
    1 point
  12. Well after reading around I think I found a solution. I did not find any functions that did what wanted at GuiTreeView Management. So I looked around and ended up Creating an event with GUIRegisterMsg of type $WM_NOTIFY. After finding similar problems and their solution code. However, it does seem a bit hacky to me though? Any other better solutions? #include <GuiMenu.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> Global $idUI = GUICreate("Reproducer", 210, 482, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_COMPOSITED) Global $TreeStyles = BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS, $TVS_HASBUTTONS, $WS_VSCROLL, $WS_HSCROLL, $TVS_DISABLEDRAGDROP, $TVS_LINESATROOT) Global $idItemTree = GUICtrlCreateTreeView(5, 5, 200, 472, $TreeStyles, $WS_EX_CLIENTEDGE) ;lets add 6 items Global $idBrowsers= GUICtrlCreateTreeViewItem("Browsers", $idItemTree) Global $idFirefox = GUICtrlCreateTreeViewItem("Firefox", $idBrowsers) Global $idChrome = GUICtrlCreateTreeViewItem("Chrome", $idBrowsers) Global $idFruit = GUICtrlCreateTreeViewItem("Fruit", $idItemTree) Global $idOranges = GUICtrlCreateTreeViewItem("Oranges", $idFruit) Global $idPears = GUICtrlCreateTreeViewItem("Pears", $idFruit) GUICtrlSetImage($idBrowsers, "imageres.dll", 5) GUICtrlSetImage($idFruit, "imageres.dll", 5) GUICtrlSetImage($idFirefox, "shell32.dll", 278) GUICtrlSetImage($idChrome, "shell32.dll", 278) GUICtrlSetImage($idOranges, "shell32.dll", 278) GUICtrlSetImage($idPears, "shell32.dll", 278) _GUICtrlTreeView_Expand($idItemTree) _GUICtrlTreeView_Sort($idItemTree) ;Let create the context menu Global $idTreeContext = GUICtrlCreateContextMenu($idItemTree) Global $idAddMenu = GUICtrlCreateMenuItem("Add New Item", $idTreeContext) Global $idDeleteMenu = GUICtrlCreateMenuItem("Delete Selected", $idTreeContext) GUISetState(@SW_SHOW, $idUI) ;Let register events Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "terminate", $idUI) GUICtrlSetOnEvent($idAddMenu , "add_item") GUICtrlSetOnEvent($idDeleteMenu , "delete_item") ;Register a windows event/msg GUIRegisterMsg($WM_NOTIFY , "RIGHTSEL_WM_NOTIFY") Func terminate() Exit EndFunc Func delete_item() Local $idSelItem = _GUICtrlTreeView_GetSelection($idItemTree) MsgBox(0,"Selected Item", "The selected item is:"&_GUICtrlTreeView_GetText($idItemTree, $idSelItem)) ;delete it just an example don't worry about childern objects _GUICtrlTreeView_Delete($idItemTree, $idSelItem) EndFunc Func add_item() Local $sName = InputBox("New Item", "Enter a name for the new item", "", "", 100, 125) If (@error=0) Then Local $idNew=GUICtrlCreateTreeViewItem($sName, $idItemTree) GUICtrlSetImage($idNew, "shell32.dll", 278) EndIf EndFunc Func RIGHTSEL_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) ;Notsure what DLLStructure functions do exactly but I feel it can be ;Performed with bitwise and bit shifting operators $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") IF (($iIDFrom=$idItemTree) AND ($iCode=$NM_RCLICK)) Then Local $iMouseX =_WinAPI_GetMousePosX (True, $hWndFrom) Local $iMouseY =_WinAPI_GetMousePosY (True, $hWndFrom) Local $hItemSel =_GUICtrlTreeView_HitTestItem($hWndFrom, $iMouseX, $iMouseY) Local $iHitStat =_GUICtrlTreeView_HitTest ($hWndFrom, $iMouseX, $iMouseY) ;Only update the selected item if right click is in the objects area If (NOT(64 < $iHitStat) AND ($iHitStat > 1)) Then If IsPtr($hItemSel)Then _GUICtrlTreeView_SelectItem($hWndFrom, $hItemSel) _GUICtrlTreeView_SetFocused($hWndFrom, $hItemSel, True) EndIf EndIf EndIF Return $GUI_RUNDEFMSG EndFunc ;do other stuff while 1 Sleep(10) WEnd
    1 point
  13. Okay here is some code I quickly wrote up that reproduces the problem. #include <GuiMenu.au3> #include <GuiTreeView.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> Global $idUI = GUICreate("Reproducer", 210, 482, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_COMPOSITED) Global $TreeStyles = BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS, $TVS_HASBUTTONS, $WS_VSCROLL, $WS_HSCROLL, $TVS_DISABLEDRAGDROP, $TVS_LINESATROOT) Global $idItemTree = GUICtrlCreateTreeView(5, 5, 200, 472, $TreeStyles, $WS_EX_CLIENTEDGE) ;lets add 6 items Global $idBrowsers = GUICtrlCreateTreeViewItem("Browsers", $idItemTree) Global $idFirefox = GUICtrlCreateTreeViewItem("Firefox", $idBrowsers) Global $idChrome = GUICtrlCreateTreeViewItem("Chrome", $idBrowsers) Global $idFruit = GUICtrlCreateTreeViewItem("Fruit", $idItemTree) Global $idOranges = GUICtrlCreateTreeViewItem("Oranges", $idFruit) Global $idPears = GUICtrlCreateTreeViewItem("Pears", $idFruit) GUICtrlSetImage($idBrowsers, "imageres.dll", 5) GUICtrlSetImage($idFruit, "imageres.dll", 5) GUICtrlSetImage($idFirefox, "shell32.dll", 278) GUICtrlSetImage($idChrome, "shell32.dll", 278) GUICtrlSetImage($idOranges, "shell32.dll", 278) GUICtrlSetImage($idPears, "shell32.dll", 278) _GUICtrlTreeView_Expand($idItemTree) _GUICtrlTreeView_Sort($idItemTree) ;Let create the context menu Global $idTreeContext = GUICtrlCreateContextMenu($idItemTree) Global $idAddMenu = GUICtrlCreateMenuItem("Add New Item", $idTreeContext) Global $idDeleteMenu = GUICtrlCreateMenuItem("Delete Selected", $idTreeContext) GUISetState(@SW_SHOW, $idUI) ;Lets register events Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "terminate", $idUI) GUICtrlSetOnEvent($idAddMenu , "add_item") GUICtrlSetOnEvent($idDeleteMenu , "delete_item") Func terminate() Exit EndFunc Func delete_item() Local $idSelItem = _GUICtrlTreeView_GetSelection($idItemTree) MsgBox(0,"Selected Item", "The selected item is:"&_GUICtrlTreeView_GetText($idItemTree, $idSelItem)) ;delete it just an example don't worry about childern objects _GUICtrlTreeView_Delete($idItemTree, $idSelItem) EndFunc Func add_item() Local $sName = InputBox("New Item", "Enter a name for the new item", "", "", 100, 125) If (@error=0) Then Local $idNew=GUICtrlCreateTreeViewItem($sName, $idItemTree) GUICtrlSetImage($idNew, "shell32.dll", 278) EndIf EndFunc ;do other stuff while 1 Sleep(10) WEnd
    1 point
×
×
  • Create New...