Leaderboard
Popular Content
Showing content with the highest reputation on 12/17/2020 in all areas
-
GUIListViewEx - BugFix Version 6 Apr 24
Siwa and 2 others reacted to pixelsearch for a topic
Maybe another approach, based on $GUI_EVENT_MOUSEMOVE ? #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example Global $iCount_Left = 20, $iCount_Right = 20, $vData, $aRet, $iEditMode = 0 ; Create GUI $hGUI = GUICreate("LVEx Example 4", 640, 430) ; Create Left ListView GUICtrlCreateLabel("Native ListView", 10, 5, 300, 35) $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 250, 300, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($cListView_Left, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetColumnWidth($cListView_Left, 0, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 83) ; Create initial array, replacement array and fill Left listview Global $aLV_List_Left[$iCount_Left + 1] = [$iCount_Left] Global $aLV_List_Left_Replace[$iCount_Left + 1] = [$iCount_Left] For $i = 1 To UBound($aLV_List_Left) - 1 $aLV_List_Left[$i] = "Tom " & $i - 1 & "|Dick " & $i - 1 & "|Harry " & $i - 1 GUICtrlCreateListViewItem($aLV_List_Left[$i], $cListView_Left) $aLV_List_Left_Replace[$i] = "Bill " & $i - 1 & "|Ben " & $i - 1 & "|Bessie " & $i - 1 Next ; Initiate LVEx - count parameter set - blue insert mark- no drag image $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 1, 0x0000FF, False) ; All columns editable _GUIListViewEx_SetEditStatus($iLV_Left_Index, "*") ; Create Right ListView GUICtrlCreateLabel("UDF ListView", 380, 5, 300, 35) $hListView_Right = _GUICtrlListView_Create($hGUI, "Peter|Paul|Mary", 380, 40, 250, 300, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER)) _GUICtrlListView_SetExtendedListViewStyle($hListView_Right, BitOr($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) _GUICtrlListView_SetColumnWidth($hListView_Right, 0, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 83) _GUICtrlListView_SetInsertMarkColor($hListView_Right, 0) ; Fill listview For $i = 0 To $iCount_Right - 1 _GUICtrlListView_AddItem($hListView_Right, "Peter " & $i) _GUICtrlListView_AddSubItem($hListView_Right, $i, "Paul " & $i, 1) _GUICtrlListView_AddSubItem($hListView_Right, $i, "Mary " & $i, 2) Next ; Read ListView content into an array $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView_Right, 0) ; Initiate LVEx - no count - green insert parameter - no drag image $iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $aLV_List_Right, 0, 0x00FF00) ; Create Edit Mode Combos GUICtrlCreateLabel("Edit Modes", 280, 50, 60, 20) GUICtrlCreateLabel("0" & @CRLF & "1" & @CRLF & "2" & @CRLF & "3", 280, 70, 10, 80) GUICtrlCreateLabel(": Single Edit" & @CRLF & ": Exit Edge" & @CRLF & ": Stay Edge" & @CRLF & ": Loop Edge", 290, 70, 65, 80) GUICtrlCreateLabel("Row Mode", 280, 140, 60, 20) $cCombo_Row = GUICtrlCreateCombo("", 280, 160, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Row, "0|1|2|3", 0) GUICtrlCreateLabel("Col Mode", 280, 200, 60, 20) $cCombo_Col = GUICtrlCreateCombo("", 280, 220, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Col, "0|1|2|3", 0) GUICtrlCreateLabel("ESC Mode", 280, 260, 75, 20) $cCombo_Reset = GUICtrlCreateCombo("", 280, 280, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Reset, "Exit Edit|Reset All", "Exit Edit") ; Create buttons $cInsert_Button = GUICtrlCreateButton("Insert", 10, 350, 200, 30) $cDelete_Button = GUICtrlCreateButton("Delete", 10, 390, 200, 30) $cReset_Button = GUICtrlCreateButton("Reset Left", 220, 350, 200, 70) $cDisplay_Left_Button = GUICtrlCreateButton("Show Left", 430, 350, 100, 30) $cDisplay_Right_Button = GUICtrlCreateButton("Show Right", 530, 350, 100, 30) $cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 30) GUISetState() ; Register for dragging and editing _GUIListViewEx_MsgRegister() ; Set the right ListView as active _GUIListViewEx_SetActive(2) Switch _GUIListViewEx_GetActive() Case 0 $sMsg = "No ListView is active" Case 1 $sMsg = "The LEFT ListView is active" & @CRLF & "<--------------------------" Case 2 $sMsg = "The RIGHT ListView is active" & @CRLF & "---------------------------->" EndSwitch MsgBox(0, "Active ListView", $sMsg) MsgBox(0, "Dragging", "You can drag and reorder the headers on the right-hand ListView" & @CRLF & "---------------------------->") While 1 Switch GUIGetMsg() ;<================================================================ Case $GUI_EVENT_MOUSEMOVE Local $aHit = _GUICtrlListView_SubItemHitTest($hListView_Right) If $aHit[0] = 5 And $aHit[1] = 2 Then ; item / subitem ToolTip("Infos displayed here...") Else ToolTip("") EndIf ;<================================================================ Case $GUI_EVENT_CLOSE, $cExit_Button Exit Case $cInsert_Button ; Prepare data for insertion Switch $aGLVEx_Data[0][1] Case 1 ; Array format with single column native ListView Global $vData[1] = ["Tom " & $iCount_Left] $iCount_Left += 1 _GUIListViewEx_Insert($vData) Case 2 ; String format with single column UDF ListView $vData = "Peter " & $iCount_Right $iCount_Right += 1 _GUIListViewEx_Insert($vData) EndSwitch Case $cDelete_Button _GUIListViewEx_Delete() Case $cReset_Button ; Note parameter required for each step ; Remove current ListView from UDF _GUIListViewEx_Close($iLV_Left_Index) ; UDF index ; Delete all items _GUICtrlListView_DeleteAllItems($cListView_Left) ; ControlID/handle ; Refill the ListView with new data For $i = 1 To UBound($aLV_List_Left_Replace) - 1 GUICtrlCreateListViewItem($aLV_List_Left_Replace[$i], $cListView_Left) ; ControlID/handle Next ; Re-initiate ListView $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left_Replace, 1, 0x0000FF, False) ; ControlID/handle ; Reset all columns editable _GUIListViewEx_SetEditStatus($iLV_Left_Index, "*") ; UDF index Case $cDisplay_Left_Button $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index) If Not @error Then _ArrayDisplay($aLV_List_Left, "Returned Left") Else MsgBox(0, "Left", "Empty Array") EndIf Case $cDisplay_Right_Button $aLV_List_Right = _GUIListViewEx_ReturnArray($iLV_Right_Index) If Not @error Then _ArrayDisplay($aLV_List_Right, "Returned Right") Else MsgBox(0, "Right", "Empty Array") EndIf Case $cCombo_Row Switch GUICtrlRead($cCombo_Row) Case 0 GUICtrlSetData($cCombo_Col, 0) Case Else If GUICtrlRead($cCombo_Col) = 0 Then GUICtrlSetData($cCombo_Col, GUICtrlRead($cCombo_Row)) EndIf EndSwitch $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Case $cCombo_Col Switch GUICtrlRead($cCombo_Col) Case 0 GUICtrlSetData($cCombo_Row, 0) Case Else If GUICtrlRead($cCombo_Row) = 0 Then GUICtrlSetData($cCombo_Row, GUICtrlRead($cCombo_Col)) EndIf EndSwitch $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Case $cCombo_Reset ; Toggle edit mode value to switch ESC modes $iEditMode *= -1 EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) ; Use combos to change EditMode If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 0 ; No event detected Case 1 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8) EndIf Case 2 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8) EndIf Case 3 MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF) Case 4 MsgBox($MB_SYSTEMMODAL, "Dragged", "From : To" & @CRLF & $vRet & @CRLF) EndSwitch WEnd Edit: I hope your Spanish class went well today and noone said : Si estudiaras más, sacarías mejores notas. Just find that sentence on a "Subjunctive – Past or Imperfect" web page3 points -
GUIListViewEx - BugFix Version 6 Apr 24
Musashi and one other reacted to pixelsearch for a topic
Done. The tooltip is on "Mary 30" in the script below. Now if you scroll vertically until "Mary 30" disappears from the LV visible area, then the tooltip won't appear anymore while the mouse hovers the 2 buttons "Show Right" or "Exit" #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example Global $iCount_Left = 20, $iCount_Right = 40, $vData, $aRet, $iEditMode = 0 ; Create GUI $hGUI = GUICreate("LVEx Example 4", 640, 430) ; Create Left ListView GUICtrlCreateLabel("Native ListView", 10, 5, 300, 35) $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 250, 300, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($cListView_Left, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetColumnWidth($cListView_Left, 0, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 83) ; Create initial array, replacement array and fill Left listview Global $aLV_List_Left[$iCount_Left + 1] = [$iCount_Left] Global $aLV_List_Left_Replace[$iCount_Left + 1] = [$iCount_Left] For $i = 1 To UBound($aLV_List_Left) - 1 $aLV_List_Left[$i] = "Tom " & $i - 1 & "|Dick " & $i - 1 & "|Harry " & $i - 1 GUICtrlCreateListViewItem($aLV_List_Left[$i], $cListView_Left) $aLV_List_Left_Replace[$i] = "Bill " & $i - 1 & "|Ben " & $i - 1 & "|Bessie " & $i - 1 Next ; Initiate LVEx - count parameter set - blue insert mark- no drag image $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 1, 0x0000FF, False) ; All columns editable _GUIListViewEx_SetEditStatus($iLV_Left_Index, "*") ; Create Right ListView GUICtrlCreateLabel("UDF ListView", 380, 5, 300, 35) ;<========================================== ; $hListView_Right = _GUICtrlListView_Create($hGUI, "Peter|Paul|Mary", 380, 40, 250, 300, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER)) Local $iLV_Width = 250, $iLV_Height = 300 $hListView_Right = _GUICtrlListView_Create($hGUI, "Peter|Paul|Mary", 380, 40, $iLV_Width, $iLV_Height, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER)) ;<========================================== _GUICtrlListView_SetExtendedListViewStyle($hListView_Right, BitOr($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) _GUICtrlListView_SetColumnWidth($hListView_Right, 0, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 83) _GUICtrlListView_SetInsertMarkColor($hListView_Right, 0) ; Fill listview For $i = 0 To $iCount_Right - 1 _GUICtrlListView_AddItem($hListView_Right, "Peter " & $i) _GUICtrlListView_AddSubItem($hListView_Right, $i, "Paul " & $i, 1) _GUICtrlListView_AddSubItem($hListView_Right, $i, "Mary " & $i, 2) Next ; Read ListView content into an array $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView_Right, 0) ; Initiate LVEx - no count - green insert parameter - no drag image $iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $aLV_List_Right, 0, 0x00FF00) ; Create Edit Mode Combos GUICtrlCreateLabel("Edit Modes", 280, 50, 60, 20) GUICtrlCreateLabel("0" & @CRLF & "1" & @CRLF & "2" & @CRLF & "3", 280, 70, 10, 80) GUICtrlCreateLabel(": Single Edit" & @CRLF & ": Exit Edge" & @CRLF & ": Stay Edge" & @CRLF & ": Loop Edge", 290, 70, 65, 80) GUICtrlCreateLabel("Row Mode", 280, 140, 60, 20) $cCombo_Row = GUICtrlCreateCombo("", 280, 160, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Row, "0|1|2|3", 0) GUICtrlCreateLabel("Col Mode", 280, 200, 60, 20) $cCombo_Col = GUICtrlCreateCombo("", 280, 220, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Col, "0|1|2|3", 0) GUICtrlCreateLabel("ESC Mode", 280, 260, 75, 20) $cCombo_Reset = GUICtrlCreateCombo("", 280, 280, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Reset, "Exit Edit|Reset All", "Exit Edit") ; Create buttons $cInsert_Button = GUICtrlCreateButton("Insert", 10, 350, 200, 30) $cDelete_Button = GUICtrlCreateButton("Delete", 10, 390, 200, 30) $cReset_Button = GUICtrlCreateButton("Reset Left", 220, 350, 200, 70) $cDisplay_Left_Button = GUICtrlCreateButton("Show Left", 430, 350, 100, 30) $cDisplay_Right_Button = GUICtrlCreateButton("Show Right", 530, 350, 100, 30) $cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 30) GUISetState() ; Register for dragging and editing _GUIListViewEx_MsgRegister() ; Set the right ListView as active _GUIListViewEx_SetActive(2) Switch _GUIListViewEx_GetActive() Case 0 $sMsg = "No ListView is active" Case 1 $sMsg = "The LEFT ListView is active" & @CRLF & "<--------------------------" Case 2 $sMsg = "The RIGHT ListView is active" & @CRLF & "---------------------------->" EndSwitch MsgBox(0, "Active ListView", $sMsg) MsgBox(0, "Dragging", "You can drag and reorder the headers on the right-hand ListView" & @CRLF & "---------------------------->") While 1 Switch GUIGetMsg() ;<================================================================ Case $GUI_EVENT_MOUSEMOVE Local $aPos = MouseGetPos() _ScreenToClient($hListView_Right, $aPos) ; $aPos ByRef will be changed (+++) . Converts mouse coords to listview coords ; ConsoleWrite($aPos[0] & " / " & $aPos[1] & @crlf) If $aPos[0] < 0 Or $aPos[0] > $iLV_Width Or $aPos[1] < 0 Or $aPos[1] > $iLV_Height Then ToolTip("") ContinueLoop EndIf Local $aHit = _GUICtrlListView_SubItemHitTest($hListView_Right) If $aHit[0] = 30 And $aHit[1] = 2 Then ; item / subitem ToolTip("Infos displayed here...") Else ToolTip("") EndIf ;<================================================================ Case $GUI_EVENT_CLOSE, $cExit_Button Exit Case $cInsert_Button ; Prepare data for insertion Switch $aGLVEx_Data[0][1] Case 1 ; Array format with single column native ListView Global $vData[1] = ["Tom " & $iCount_Left] $iCount_Left += 1 _GUIListViewEx_Insert($vData) Case 2 ; String format with single column UDF ListView $vData = "Peter " & $iCount_Right $iCount_Right += 1 _GUIListViewEx_Insert($vData) EndSwitch Case $cDelete_Button _GUIListViewEx_Delete() Case $cReset_Button ; Note parameter required for each step ; Remove current ListView from UDF _GUIListViewEx_Close($iLV_Left_Index) ; UDF index ; Delete all items _GUICtrlListView_DeleteAllItems($cListView_Left) ; ControlID/handle ; Refill the ListView with new data For $i = 1 To UBound($aLV_List_Left_Replace) - 1 GUICtrlCreateListViewItem($aLV_List_Left_Replace[$i], $cListView_Left) ; ControlID/handle Next ; Re-initiate ListView $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left_Replace, 1, 0x0000FF, False) ; ControlID/handle ; Reset all columns editable _GUIListViewEx_SetEditStatus($iLV_Left_Index, "*") ; UDF index Case $cDisplay_Left_Button $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index) If Not @error Then _ArrayDisplay($aLV_List_Left, "Returned Left") Else MsgBox(0, "Left", "Empty Array") EndIf Case $cDisplay_Right_Button $aLV_List_Right = _GUIListViewEx_ReturnArray($iLV_Right_Index) If Not @error Then _ArrayDisplay($aLV_List_Right, "Returned Right") Else MsgBox(0, "Right", "Empty Array") EndIf Case $cCombo_Row Switch GUICtrlRead($cCombo_Row) Case 0 GUICtrlSetData($cCombo_Col, 0) Case Else If GUICtrlRead($cCombo_Col) = 0 Then GUICtrlSetData($cCombo_Col, GUICtrlRead($cCombo_Row)) EndIf EndSwitch $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Case $cCombo_Col Switch GUICtrlRead($cCombo_Col) Case 0 GUICtrlSetData($cCombo_Row, 0) Case Else If GUICtrlRead($cCombo_Row) = 0 Then GUICtrlSetData($cCombo_Row, GUICtrlRead($cCombo_Col)) EndIf EndSwitch $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Case $cCombo_Reset ; Toggle edit mode value to switch ESC modes $iEditMode *= -1 EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) ; Use combos to change EditMode If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 0 ; No event detected Case 1 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8) EndIf Case 2 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8) EndIf Case 3 MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF) Case 4 MsgBox($MB_SYSTEMMODAL, "Dragged", "From : To" & @CRLF & $vRet & @CRLF) EndSwitch WEnd ;<============================================ Func _ScreenToClient($hWindow, ByRef $aCoord) ; convert screen coords to $hWindow client coords (i.e mouse to listview, or listview to GUI, or mouse to header...) ; no problem if $aCoord got more than 2 elements, only the first 2 elements will be updated Local $tPoint = DllStructCreate("int X;int Y") DllStructSetData($tPoint, "X", $aCoord[0]) DllStructSetData($tPoint, "Y", $aCoord[1]) _WinAPI_ScreenToClient($hWindow, $tPoint) $aCoord[0] = DllStructGetData($tPoint, "X") $aCoord[1] = DllStructGetData($tPoint, "Y") ; ByRef modified the Array in the calling function (+++) EndFunc ;==>_ScreenToClient ;<============================================ This script should be amended in case your listview height or width change during the execution of the script. Also, if you want it to be a bit more precise, you should take care of the listview header height and the 2 eventual scrollbars (horizontal & vertical) so the tooltip won't be displayed when your mouse hover upon them while the "tooltipped" cell is just under them. Anyway, you got now a good basis to work on, because mouse coords are constantly compared to listview boundaries and : 1) If mouse coords are outside the LV boundaries => ToolTip("") 2) If they're inside => _GUICtrlListView_SubItemHitTest() Good luck Edit: I just notice you edited your last post, gonna read it again.2 points -
I don't know if you are like me, but I am always searching for that specific code I wrote over the years, but cannot find it. It was way too exhausting to look at 1k+ scripts. And Windows Explorer is not the best tool to do such exploration. So I made this little script that save me tons of time. Hope you will find it useful too. You can adjust default search folders and type of files you want to search for, but you can also change it at runtime. To use multiple filters separate them with ";" Let me know if you have any suggestion to enhance the tool. Version 2023-12-27 * Code revision : 3.3.16.1 now required Version 2023-05-10 * Sets children flag on first drawn list Version 2021-04-06 * Context menu modified to allow clipping file name and line content Version 2020-11-21 * Allows only 1 running instance of the script * Added right-click support on Tray to exit script Version 2020-06-29 * Added Copy File Name to context menu (helps to copy include files names) Version 2020-04-22 * Added icons to main buttons * Added informative box to describe progress and results of a search * Increased robustness of the GUI * Open Button enabled only under the right conditions * Added Tooltip on filter field to describe how to enter multiple criteria * Forced a minimum Window size Version 2020-04-18 * Added support of Context Menu in Tree View * Added support of Tray * Minimizes on Tray Version 2020-04-12 * Added DPI awareness * Added Enter Key functionality to start a search Version 2020-04-09 * Changed base size of the GUI to make it wider * Made the window resizable * Added Reset button * Shown busy cursor more appropriately * Corrected bug of first line displayed Thanks all for your input. SearchContent.au31 point
-
AutoIt Snippets
BigDaddyO reacted to seadoggie01 for a topic
While I hate this kind of file, I recently had to re-write an Excel VBA script that wrote the worksheet to a fixed width format file. It isn't perfect, but this is what I have so far: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Export_FixedWidth ; Description ...: Exports an array to a file using a fixed width format ; Syntax ........: _Export_FixedWidth($avData, $aiWidth, $aiPrecision, $sFile[, $sNewLine = Default]) ; Parameters ....: $avData - a 2D array of variants. ; $aiWidth - a 1D array of integers. ; $aiPrecision - a 1D array of integers. Default copies $aiWidth. ; $sFile - full file path to save as or a file handle. ; $sNewLine - [optional] newline. Default is @CRLF. ; Return values .: Success - True ; Failure - False and sets @error: ; |1 - $avData isn't a 2D array ; |2 - $avData has more columns than (@extended) 1 - $aiWidth or 2 - $aiPrecision ; |3 - Unable to write data to $sFile ; Author ........: Seadoggie01 ; Modified ......: December 17, 2020 ; Remarks .......: $aiWidth's and $aiPrecision's sizes must match $avData's column count. ; If $sFile is a handle, it will not be closed ; Data is right aligned; set $aiWidth's value to negative to right align data. ; +$aiPrecision uses the absolute value (helpful if $aiPrecision = $aiWidth) ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _Export_FixedWidth($avData, $aiWidth, $aiPrecision, $sFile, $sNewLine = Default) If IsKeyword($aiPrecision) Then $aiPrecision = $aiWidth If IsKeyword($sNewLine) Then $sNewLine = @CRLF ; Ensure 2D array If UBound($avData, 0) <> 2 Then Return SetError(1, 0, False) ; Check sizes of the arrays If UBound($aiWidth) <> UBound($avData, 2) Then Return SetError(2, 1, False) If UBound($aiPrecision) <> UBound($avData, 2) Then Return SetError(2, 2, False) Local $sExportText ; For each row For $iRow = 0 To UBound($avData) - 1 ; For each column For $iColumn = 0 To UBound($avData, 2) - 1 ; Format the data as a string using the width and precision assigned by the user $sExportText &= StringFormat("%" & (-1 * $aiWidth[$iColumn]) & "." & Abs($aiPrecision[$iColumn]) & "s", $avData[$iRow][$iColumn]) Next $sExportText &= $sNewLine Next If Not FileWrite($sFile, $sExportText) Then Return SetError(3, 0, False) Return True EndFunc As the VBA was looping through each cell, reading it (and the precision), and writing it to file, it was taking upwards of 10 minutes as the worksheet was 72 columns x 15367 rows (~1.1 M cells). I'm very impatient and this was just too much. Now it takes less than a second to write the data I lied, I needed more error checking. 🤦♂️ However, 24 seconds is still much better1 point -
GUIListViewEx - BugFix Version 6 Apr 24
pixelsearch reacted to Siwa for a topic
That was exactly what I meant, sorry If I couldn't put my script here, it is getting bigger and bigger, and it needs an excel file to load content from. it is a smart solution, but not an appropriate one. My main goal is to solve it with the right script. But yours will do exactly what is needed. Edit : This is my solution based on your suggestion, ( changed the way I read the content to use _GUICtrlListView_GetItemText, which reads live content ) : Local $aHit = _GUICtrlListView_SubItemHitTest($hcListView) For $i=0 To UBound($aLVArray)-1 If $aHit[0] = $i And $aHit[1] = 5 Then ; item / subitem Local $Mouse_Pos = MouseGetPos() Local $LV_Pos = ControlGetPos($hMainGUI, "", $cListView) Local $GUI_Pos = WinGetPos("****") If $Mouse_Pos[0]<$GUI_Pos[0]+$LV_Pos[2] And $GUI_Pos[0]+$LV_Pos[0]<$Mouse_Pos[0] And $Mouse_Pos[1]<$GUI_Pos[1]+$LV_Pos[3] And $GUI_Pos[1]+$LV_Pos[1]<$Mouse_Pos[1] Then If _GUICtrlListView_GetItemText($hcListView, $i,5) > "" Then ToolTip(_GUICtrlListView_GetItemText($hcListView, $i,6)) Else ToolTip("") EndIf Else ToolTip("") EndIf ElseIf $aHit[0] = $i And $aHit[1] = 1 Then ToolTip("") ElseIf $aHit[0] = $i And $aHit[1] = 2 Then ToolTip("") ElseIf $aHit[0] = $i And $aHit[1] = 3 Then ToolTip("") ElseIf $aHit[0] = $i And $aHit[1] = 4 Then ToolTip("") EndIf Next1 point -
GUIListViewEx - BugFix Version 6 Apr 24
Siwa reacted to pixelsearch for a topic
@Siwa: I can reproduce the issue you described (by modifying the script above, changing $iCount_Right from 20 to 40, then "tooltipping" on Mary 30 after a change to $aHit[0] = 30) Now that there is a vertical scrolling in the listview (which wasn't the case in the example above), when "Mary 30" isn't visible in the listview but "hidden" under the buttons "Show Right" or "Exit", then the tooltip is displayed anyway when the mouse hovers the hidden "Mary 30" cell, I hope this is what you mean. A solution could be to test the mouse coords within the $GUI_EVENT_MOUSEMOVE event and when mouse coords are outside the listview boundaries, then prevent the tooltip for appearing. This test could be the 1st test to check, so while mouse coords are outside the listview boundaries, then there's no use to do the SubItemHitTest. Theorically it should work, I'll test it after errands & dinner. If anyone got another idea, please let us know, thanks1 point -
Changing Font and Color of a Assinged Label
FrancescoDiMuro reacted to KaFu for a topic
You're right if you use it directly after creation, but with eval you can change it back and forth later on :).1 point -
pixelsearch, Very nice! M23 P.S. And there was a phrase very like that - but rather more complimentary1 point
-
Datatype from COM/Object
FrancescoDiMuro reacted to mLipok for a topic
I think that we should ask @trancexx . Could you take a look @trancexx ?1 point -
Changing Font and Color of a Assinged Label
Aelc reacted to FrancescoDiMuro for a topic
@KaFu You don't need to use Eval at all: #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= Global $frmLabels = GUICreate("Labels", 405, 293, 302, 218) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _CreateLabels() _GetLabelTexts() Func ExitApplication() GUIDelete($frmLabels) Exit EndFunc Func _CreateLabels() For $i = 1 To 10 Step 1 Assign("lblLabel" & $i, GUICtrlCreateLabel("Some text " & $i, 8, 8 + ($i * 20), 100, 20), $ASSIGN_FORCEGLOBAL) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, (Mod($i, 2) = 0 ? 0x00FF00 : 0xFF0000)) Next EndFunc Func _GetLabelTexts() Local $strLabel For $i = 1 To 10 Step 1 $strLabel = Eval("lblLabel" & $i) ConsoleWrite($strLabel & " " & GUICtrlRead($strLabel) & @CRLF) Next EndFunc While 1 Sleep(100) WEnd1 point -
Extracting part of a file name?
Musashi reacted to AspirinJunkie for a topic
For this reason, among others, it is a good idea to clean up the path beforehand with _WinAPI_GetFullPathName() (file does not have to exist here). Then relative paths are evaluated, double backslashes are removed and slashes are converted to backslashes.1 point -
pixelsearch, Try pulling the mouse to the right off "Mary 5" - the tooltip remains visible until you reenter one of the ListViews and a new $LVN_HOTTRACK message is sent. This is the same problem I found in my tests yesterday and what I will be trying to solve today once my Spanish class is over. Imperfect subjunctives in indirect speech today - my head hurts already! M231 point
-
What is the difference between this coding?
ReconX reacted to JockoDundee for a topic
In addition to being less verbose than If/ElseIf, the Switch Case has the option of using a Continue Case statement, which can act as a logical waterfall, useful sometimes e.g. state machines. From the example: #include <MsgBoxConstants.au3> Example() Func Example() Local $sName = InputBox("", "Please enter a word.", "", " M", Default, Default, Default, Default, 10) Local $sMsg = "" Switch @error Case 2 $sMsg = "Timeout " ContinueCase Case 1 ; Continuing previous case $sMsg &= "Cancellation" Case 0 Switch $sName Case "a", "e", "i", "o", "u" $sMsg = "Vowel" Case "QP" $sMsg = "Mathematics" Case "Q" To "QZ" $sMsg = "Science" Case Else $sMsg = "Others" EndSwitch Case Else $sMsg = "Something went horribly wrong." EndSwitch MsgBox($MB_SYSTEMMODAL, "", $sMsg) EndFunc ;==>Example1 point -
Since you are going down the path of code optimization, may I offer another tip? A good coding practice is to eliminate redundant code where feasible. A great opportunity which stands out looking at your code is the FileSelectFolder calls. I would consider turning that into a function and calling the function instead. Something like: Case $bDVD _SetDirectoryFromFolderSelection($hDVD) Case $bBLU _SetDirectoryFromFolderSelection($hBLU) Case $b4K _SetDirectoryFromFolderSelection($h4K) Case $b3D _SetDirectoryFromFolderSelection($h3D) Func _SetDirectoryFromFolderSelection($hCtrl) Local $sFolder = FileSelectFolder("Select a folder...", "%CSIDL_DRIVES%") If @error Then MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.") Else GUICtrlSetData($hCtrl, $sFolder) EndIf EndFunc1 point
-
@ReconX They essentially perform the same task (if else logic vs. switch case), but I think Switch Case is optimized (more efficient processor time wise) compared to a lengthy if else chain. @Aelc has a good point of not performing GUICtrlRead over and over. It is just more efficient to call it once, store the result in a variable, then compare the variable. @jchd Also has a point that as written, it wouldn't function, but I think you were just asking about the logic differences.1 point
-
In your first snippet, the Case is by itself only part of some control structure (Select or Switch), so it isn't a valid part of code by itself. In your second snippet, you misinterpret the semantics of the control structure. I see that @Aelc just posted how to use Switch and what <expression> means in the help on Switch.1 point
-
use it like Switch GUICtrlRead($hCombo) Case $aArray[0] $fileDIR = GUICtrlRead($hDVD) GUICtrlRead($FileList) GUICtrlSetData($listview, $FileList) Case $aArray[1] $fileDIR = GUICtrlRead($hBLU) GUICtrlRead($FileList) GUICtrlSetData($listview, $FileList) Case $aArray[2] $fileDIR = GUICtrlRead($h4K) Case $aArray[3] $fileDIR = GUICtrlRead($h3D) EndSwitch so you wouldn't have to call the GUICtrlRead() for every statement which means it should be faster. also it should be faster in general. additional i would say it's more clearer to script with Switch instead of ElseIf especially when you have more statements to declare. You can easily add an "OR" statement with just a "," like Switch GUICtrlRead($hCombo) Case $aArray[0],$aArray[1] $fileDIR = GUICtrlRead($hDVD) GUICtrlRead($FileList) GUICtrlSetData($listview, $FileList) Case $aArray[2], $aArray[3] $fileDIR = GUICtrlRead($h4K) EndSwitch in this case you added here it wouldn't make sense at all, but in other cases it's faster to inject.1 point
-
GUIListViewEx - BugFix Version 6 Apr 24
Siwa reacted to pixelsearch for a topic
I just experimented it on Melba23's example GLVEx_Example_4.au3 (found in the zip package) and it seems to work. Modified / added code is found below, between commented lines starting / ending with ;<=========== #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example Global $iCount_Left = 20, $iCount_Right = 20, $vData, $aRet, $iEditMode = 0 ; Create GUI $hGUI = GUICreate("LVEx Example 4", 640, 430) ; Create Left ListView GUICtrlCreateLabel("Native ListView", 10, 5, 300, 35) $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 250, 300, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($cListView_Left, $LVS_EX_FULLROWSELECT) _GUICtrlListView_SetColumnWidth($cListView_Left, 0, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 83) ; Create initial array, replacement array and fill Left listview Global $aLV_List_Left[$iCount_Left + 1] = [$iCount_Left] Global $aLV_List_Left_Replace[$iCount_Left + 1] = [$iCount_Left] For $i = 1 To UBound($aLV_List_Left) - 1 $aLV_List_Left[$i] = "Tom " & $i - 1 & "|Dick " & $i - 1 & "|Harry " & $i - 1 GUICtrlCreateListViewItem($aLV_List_Left[$i], $cListView_Left) $aLV_List_Left_Replace[$i] = "Bill " & $i - 1 & "|Ben " & $i - 1 & "|Bessie " & $i - 1 Next ; Initiate LVEx - count parameter set - blue insert mark- no drag image $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 1, 0x0000FF, False) ; All columns editable _GUIListViewEx_SetEditStatus($iLV_Left_Index, "*") ; Create Right ListView GUICtrlCreateLabel("UDF ListView", 380, 5, 300, 35) $hListView_Right = _GUICtrlListView_Create($hGUI, "Peter|Paul|Mary", 380, 40, 250, 300, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $WS_BORDER)) _GUICtrlListView_SetExtendedListViewStyle($hListView_Right, BitOr($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) _GUICtrlListView_SetColumnWidth($hListView_Right, 0, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 83) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 83) _GUICtrlListView_SetInsertMarkColor($hListView_Right, 0) ; Fill listview For $i = 0 To $iCount_Right - 1 _GUICtrlListView_AddItem($hListView_Right, "Peter " & $i) _GUICtrlListView_AddSubItem($hListView_Right, $i, "Paul " & $i, 1) _GUICtrlListView_AddSubItem($hListView_Right, $i, "Mary " & $i, 2) Next ; Read ListView content into an array $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView_Right, 0) ; Initiate LVEx - no count - green insert parameter - no drag image $iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $aLV_List_Right, 0, 0x00FF00) ; Create Edit Mode Combos GUICtrlCreateLabel("Edit Modes", 280, 50, 60, 20) GUICtrlCreateLabel("0" & @CRLF & "1" & @CRLF & "2" & @CRLF & "3", 280, 70, 10, 80) GUICtrlCreateLabel(": Single Edit" & @CRLF & ": Exit Edge" & @CRLF & ": Stay Edge" & @CRLF & ": Loop Edge", 290, 70, 65, 80) GUICtrlCreateLabel("Row Mode", 280, 140, 60, 20) $cCombo_Row = GUICtrlCreateCombo("", 280, 160, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Row, "0|1|2|3", 0) GUICtrlCreateLabel("Col Mode", 280, 200, 60, 20) $cCombo_Col = GUICtrlCreateCombo("", 280, 220, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Col, "0|1|2|3", 0) GUICtrlCreateLabel("ESC Mode", 280, 260, 75, 20) $cCombo_Reset = GUICtrlCreateCombo("", 280, 280, 75, 20, 0x3) ; $CBS_DROPDOWNLIST GUICtrlSetData($cCombo_Reset, "Exit Edit|Reset All", "Exit Edit") ; Create buttons $cInsert_Button = GUICtrlCreateButton("Insert", 10, 350, 200, 30) $cDelete_Button = GUICtrlCreateButton("Delete", 10, 390, 200, 30) $cReset_Button = GUICtrlCreateButton("Reset Left", 220, 350, 200, 70) $cDisplay_Left_Button = GUICtrlCreateButton("Show Left", 430, 350, 100, 30) $cDisplay_Right_Button = GUICtrlCreateButton("Show Right", 530, 350, 100, 30) $cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 30) GUISetState() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; next line = syntax reminder pasted from GUIListViewEx.au3 ; _GUIListViewEx_MsgRegister([$fNOTIFY = True, [$fMOUSEMOVE = True, [$fLBUTTONUP = True, [ $fSYSCOMMAND = True]]]]) ; Register for dragging and editing ; _GUIListViewEx_MsgRegister() ; original line commented as WM_NOTIFY is registered in this script. ; "only set unregistered messages in _GUIListViewEx_MsgRegister" _GUIListViewEx_MsgRegister(False, True, True, True) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Set the right ListView as active _GUIListViewEx_SetActive(2) Switch _GUIListViewEx_GetActive() Case 0 $sMsg = "No ListView is active" Case 1 $sMsg = "The LEFT ListView is active" & @CRLF & "<--------------------------" Case 2 $sMsg = "The RIGHT ListView is active" & @CRLF & "---------------------------->" EndSwitch MsgBox(0, "Active ListView", $sMsg) MsgBox(0, "Dragging", "You can drag and reorder the headers on the right-hand ListView" & @CRLF & "---------------------------->") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cExit_Button Exit Case $cInsert_Button ; Prepare data for insertion Switch $aGLVEx_Data[0][1] Case 1 ; Array format with single column native ListView Global $vData[1] = ["Tom " & $iCount_Left] $iCount_Left += 1 _GUIListViewEx_Insert($vData) Case 2 ; String format with single column UDF ListView $vData = "Peter " & $iCount_Right $iCount_Right += 1 _GUIListViewEx_Insert($vData) EndSwitch Case $cDelete_Button _GUIListViewEx_Delete() Case $cReset_Button ; Note parameter required for each step ; Remove current ListView from UDF _GUIListViewEx_Close($iLV_Left_Index) ; UDF index ; Delete all items _GUICtrlListView_DeleteAllItems($cListView_Left) ; ControlID/handle ; Refill the ListView with new data For $i = 1 To UBound($aLV_List_Left_Replace) - 1 GUICtrlCreateListViewItem($aLV_List_Left_Replace[$i], $cListView_Left) ; ControlID/handle Next ; Re-initiate ListView $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left_Replace, 1, 0x0000FF, False) ; ControlID/handle ; Reset all columns editable _GUIListViewEx_SetEditStatus($iLV_Left_Index, "*") ; UDF index Case $cDisplay_Left_Button $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index) If Not @error Then _ArrayDisplay($aLV_List_Left, "Returned Left") Else MsgBox(0, "Left", "Empty Array") EndIf Case $cDisplay_Right_Button $aLV_List_Right = _GUIListViewEx_ReturnArray($iLV_Right_Index) If Not @error Then _ArrayDisplay($aLV_List_Right, "Returned Right") Else MsgBox(0, "Right", "Empty Array") EndIf Case $cCombo_Row Switch GUICtrlRead($cCombo_Row) Case 0 GUICtrlSetData($cCombo_Col, 0) Case Else If GUICtrlRead($cCombo_Col) = 0 Then GUICtrlSetData($cCombo_Col, GUICtrlRead($cCombo_Row)) EndIf EndSwitch $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Case $cCombo_Col Switch GUICtrlRead($cCombo_Col) Case 0 GUICtrlSetData($cCombo_Row, 0) Case Else If GUICtrlRead($cCombo_Row) = 0 Then GUICtrlSetData($cCombo_Row, GUICtrlRead($cCombo_Col)) EndIf EndSwitch $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col)) Case $cCombo_Reset ; Toggle edit mode value to switch ESC modes $iEditMode *= -1 EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) ; Use combos to change EditMode If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 0 ; No event detected Case 1 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8) EndIf Case 2 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8) EndIf Case 3 MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF) Case 4 MsgBox($MB_SYSTEMMODAL, "Dragged", "From : To" & @CRLF & $vRet & @CRLF) EndSwitch WEnd ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; "call the relevant _GUIListViewEx_WM_#####_Handler from within the existing handler" _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode ; , $iIDFrom $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") ; $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") Switch $hWndFrom Case $hListView_Right Switch $iCode Case $LVN_HOTTRACK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) If $tInfo.Item = 5 And $tInfo.SubItem = 2 Then ToolTip("Infos displayed here...") Else ToolTip("") EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ToolTip's on "Mary 5"1 point -
Easy way around without GDIPlus: ;coded by UEZ build 2013-08-15 #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPISys.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172; $IMAGE_BITMAP = 0 Global $iW = 400, $iH = 25, $iBGColor = 0xFFFFFF Global Const $hGUI = GUICreate("Strip Progressbar", 600, 100) GUISetBkColor(0x404040) Global $iBtn = GUICtrlCreateButton("Start", 40, 20, 60, 60) #Region new from funkey Global Const $hHelp = GUICreate("", $iW, $iH, 150, 37, $WS_CHILD, 0, $hGui) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW, $iH) _WinAPI_SetParent($hHelp, $hGui) Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20) _WinAPI_SetWindowRgn($hHelp, $hRgn) #EndRegion GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $hHelp) GUISetState(@SW_SHOW, $hGUI) Global $hHBmp_BG, $hB, $iSleep = 30 Global $fPerc, $fPercPrev, $iLoop, $aPos, $iPosX, $iPosY Global $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xe8e5d9]] Global $iRandom, $iColorTP, $hTooltip _Init() Global $iDeltaX = _WinAPI_GetSystemMetrics(7) Global $iDeltaY = _WinAPI_GetSystemMetrics(4) + _WinAPI_GetSystemMetrics(33) Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ToolTip("") GUIRegisterMsg($WM_TIMER, "") _WinAPI_DeleteObject($hHBmp_BG) _GDIPlus_Shutdown() GUIDelete() Exit Case $iBtn $fPerc = 0 $iRandom = Random(0, UBound($aColors) - 1, 1) $iColorTP = BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF), -16) + BitAND(0x0000FF00, $aColors[$iRandom][1]) + BitShift(BitAND(BitAND(0x00FFFFFF, $aColors[$iRandom][1]), 0xFF0000), 16) ;convert to BGR GUIRegisterMsg($WM_TIMER, "PlayAnim") DllCall("user32.dll", "int", "SetTimer", "hwnd", $hGUI, "int", 0, "int", $iSleep, "int", 0) EndSwitch Until False Func _Init() $hHBmp_BG = _GDIPlus_StripProgressbar(0, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], "") $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) EndFunc ;==>_Init Func PlayAnim() Local $sText = "Loading...", $i, $iCalc1, $iCalc2 $fPerc += 0.5 If $fPerc >= 100.5 Then GUIRegisterMsg($WM_TIMER, "") $sText = "Done" EndIf $iLoop = $fPerc - $fPercPrev $fPercPrev = $fPerc For $i = $iLoop To 0 Step - 1 $iCalc1 = ($fPerc - $i) $hHBmp_BG = _GDIPlus_StripProgressbar($iCalc1, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[$iRandom][0], $aColors[$iRandom][1], $sText) $hB = GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBmp_BG) If $hB Then _WinAPI_DeleteObject($hB) _WinAPI_DeleteObject($hHBmp_BG) $aPosCtrl = ControlGetPos($hGUI, 0, $iPic) $aPosGUI = WinGetPos($hGUI) $iPosX = $aPosCtrl[0] + $aPosGUI[0] + $iDeltaX $iPosY = $aPosCtrl[1] + $aPosGUI[1] + $aPosCtrl[3] + $iDeltaY - 2 If $iCalc1 >= 100.5 Then $iCalc1 = 100 $iCalc2 = $iPosX + ($fPerc - $i) / 100 * $iW - 1 If $iCalc2 >= $iPosX + $iW Then $iCalc2 = $iPosX + $iW ToolTip(StringFormat("%02d %", $iCalc1), $iCalc2, $iPosY, "", "", 3) $hTooltip = WinGetHandle(StringFormat("%02d %", ($fPerc - $i))) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hTooltip, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $hTooltip, "int", 1043, "int", $iColorTP, "int", 0) Next If $fPerc >= 100.5 Then Sleep(750) ToolTip("") EndIf EndFunc ;==>PlayAnim Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0x000000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True) If $fPerc < 0 Then $fPerc = 0 If $fPerc > 100 Then $fPerc = 100 Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui) Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iH) Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp) _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Bmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY) Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12) Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize) _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor) Local Static $iX = 0 For $iY = 0 To $iH - 1 Switch $iDir Case 1 _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen) Case Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen) _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen) EndSwitch Next Local $tPoint1 = DllStructCreate("float;float") Local $tPoint2 = DllStructCreate("float;float") DllStructSetData($tPoint1, 1, $iW / 2) ;x1 DllStructSetData($tPoint2, 1, $iW / 2) ;x2 Local $hLineBrush If $bFlip Then _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2) DllStructSetData($tPoint1, 2, $iH / 3) ;y1 DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush) Else _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2) DllStructSetData($tPoint1, 2, 0) ;y1 DllStructSetData($tPoint2, 2, $iH / 3) ;y2 $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0) $hLineBrush = $hLineBrush[6] _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush) EndIf $iX = Mod($iX + $iSpeed, $iWidth) Local $hTextureBrush = _GDIPlus_TextureCreate($hBmp) _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush) If $bFlip Then _GDIPlus_ImageRotateFlip($hBitmap, 6) _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4) Local $hBrush = _GDIPlus_BrushCreateSolid(0x40000000 + $iTextColor) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 5, 2) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) _GDIPlus_StringFormatSetAlign($hFormat, 1) ;Center text _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush) ;Loading text _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_PenDispose($hPen2) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_GraphicsDispose($hCtxt_Bmp) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_BrushDispose($hTextureBrush) _GDIPlus_BrushDispose($hLineBrush) If $bHBitmap Then Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBITMAP EndIf Return $hBitmap EndFunc ;==>_GDIPlus_StripProgressbar;coded by UEZ build 2013-08-15 Not ideal code part for border: #Region new from funkey Global Const $hHelp = GUICreate("", $iW + 16, $iH + 7, 150, 47, $WS_CHILD, 0, $hGui) GUISetBkColor(0x000000) Global Const $iPic = GUICtrlCreatePic("", 8, 3, $iW , $iH) _WinAPI_SetParent($hHelp, $hGui) Global $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 16, $iH + 7, 20, 20) _WinAPI_SetWindowRgn($hHelp, $hRgn) #EndRegion Better solution for border: #Region new from funkey Global Const $hHelp1 = GUICreate("", $iW + 6, $iH + 6, 150, 47, $WS_CHILD, 0, $hGui) _WinAPI_SetParent($hHelp1, $hGui) GUISetBkColor(0x000000) Global Const $hHelp2 = GUICreate("", $iW, $iH, 3, 3, $WS_CHILD, 0, $hHelp1) _WinAPI_SetParent($hHelp2, $hHelp1) Global Const $iPic = GUICtrlCreatePic("", 0, 0, $iW , $iH) Global $hRgn1 = _WinAPI_CreateRoundRectRgn(0, 0, $iW + 6, $iH + 6, 25, 25) Global $hRgn2 = _WinAPI_CreateRoundRectRgn(0, 0, $iW, $iH, 20, 20) _WinAPI_SetWindowRgn($hHelp1, $hRgn1) _WinAPI_SetWindowRgn($hHelp2, $hRgn2) #EndRegion1 point
-
Hi guys/girls! I'm gonna share this UDF I made today. It allows you to easily create TCP servers and set actions depending on three events: OnConnect, OnDisconnect and OnReceive. It is also multi client (you can set the clients limit) and you can also bind a Console-based executable to the socket (similar to -e parameter in NetCat). This feature is useful if you want to use some Console UDF to create your TCP server and don't want to mix it with the TCP functions. Also, as it runs on background just firing events, it won't pause your script while listening/receiving, so you can do anything else (stop and restart the server, allow the user to click buttons or just wait on an infinite loop) that your callbacks will be called once the event is fired. It's also very easy to use. See this examples: Example #1: A basic server By running this (then connecting to the server using Netcat), you will receive a message box telling you when some user connects or disconnects (the socket ID and his IP address is passed as parameter to your callback function) and also when the user sends something over the TCP socket (the data sent is passed as parameter). #cs Download netcat at https://eternallybored.org/misc/netcat/ Execute this script Run in CMD: nc -vv 127.0.0.1 8081 #ce #include "TCPServer.au3" ; First we set the callback functions for the three events (none of them is mandatory) _TCPServer_OnConnect("connected") _TCPServer_OnDisconnect("disconnect") _TCPServer_OnReceive("received") ; And some parameters _TCPServer_DebugMode(True) _TCPServer_SetMaxClients(10) ; Finally we start the server at port 8081 at any interface _TCPServer_Start(8081) Func connected($iSocket, $sIP) MsgBox(0, "Client connected", "Client " & $sIP & " connected!") _TCPServer_Broadcast('new client connected guys', $iSocket) _TCPServer_Send($iSocket, "Hey! Write something ;)" & @CRLF) _TCPServer_SetParam($iSocket, "will write") EndFunc ;==>connected Func disconnect($iSocket, $sIP) MsgBox(0, "Client disconnected", "Client " & $sIP & " disconnected from socket " & $iSocket) EndFunc ;==>disconnect Func received($iSocket, $sIP, $sData, $sPar) MsgBox(0, "Data received from " & $sIP, $sData & @CRLF & "Parameter: " & $sPar) _TCPServer_Send($iSocket, "You wrote: " & $sData) _TCPServer_SetParam($iSocket, 'will write again') EndFunc ;==>received While 1 Sleep(100) WEnd Example #2: A basic HTTP server (just one page, as it is just an example) In this example, we run this code and point our browser to the address mentioned on the comments. A basic "It works!" page is show. #cs Run this script Point your browser to http://localhost:8081/ #ce #include "TCPServer.au3" _TCPServer_OnReceive("received") _TCPServer_DebugMode(True) _TCPServer_SetMaxClients(10) _TCPServer_Start(8081) Func received($iSocket, $sIP, $sData, $sParam) _TCPServer_Send($iSocket, "HTTP/1.0 200 OK" & @CRLF & _ "Content-Type: text/html" & @CRLF & @CRLF & _ "<h1>It works!</h1>" & @CRLF & _ "<p>This is the default web page for this server.</p>" & @CRLF & _ "<p>However this server is just a 26-lines example.</p>") _TCPServer_Close($iSocket) EndFunc ;==>received While 1 Sleep(100) WEnd Example #3: A telnet-like server (Command Prompt bound to the socket after password requesting) By running this example and connecting with Netcat, we will be asked for a password, which is 12345 as we set on the script. If the password is correct, we will see the Command Prompt live-updated (try running a ping to some server, for example). #cs Download netcat at https://eternallybored.org/misc/netcat/ Execute this script Run in CMD: nc -vv 127.0.0.1 8081 #ce #include "TCPServer.au3" Global $sPassword = "12345" ; input server password here _TCPServer_OnConnect("connected") _TCPServer_OnDisconnect("disconnect") _TCPServer_OnReceive("received") _TCPServer_DebugMode(True) _TCPServer_SetMaxClients(10) _TCPServer_Start(8081) Func connected($iSocket, $sIP) _TCPServer_Send($iSocket, "Welcome! Please input password: ") _TCPServer_SetParam($iSocket, 'login') EndFunc ;==>connected Func disconnect($iSocket, $sIP) MsgBox(0, "Client disconnected", "Client " & $sIP & " disconnected from socket " & $iSocket) EndFunc ;==>disconnect Func received($iSocket, $sIP, $sData, $sParam) If $sParam = "login" Then If $sData <> $sPassword Then _TCPServer_Send($iSocket, "Wrong password. Try again: ") Return Else _TCPServer_SetParam($iSocket, 'command') _TCPServer_BindAppToSocket($iSocket, 'cmd.exe') EndIf ElseIf $sParam = "command" Then _TCPServer_SendToBound($iSocket, $sData) EndIf EndFunc ;==>received While 1 Sleep(100) WEnd The limit is your imagination? Well, no sure. We have this limit: You can't create more than one server with this UDF in the same script. However, you can pause and resume (read 'stop and start again') your server at any time in your script, without having to reset the server settings. And of course you can have many clients (or just one, it's your choice!) in the same server. Or run multiple instances.Functions list: _TCPServer_Start _TCPServer_Stop _TCPServer_Close _TCPServer_Send _TCPServer_Broadcast _TCPServer_SetParam _TCPServer_BindAppToSocket _TCPServer_SendToBound _TCPServer_UnBindAppToSocket _TCPServer_GetMaxClients _TCPServer_IsServerActive _TCPServer_ListClients _TCPServer_OnConnect _TCPServer_OnDisconnect _TCPServer_OnReceive _TCPServer_SetMaxClients _TCPServer_DebugMode _TCPServer_AutoTrim _TCPServer_SocketToIP _TCPServer_SocketToConnID _TCPServer_ConnIDToSocket Help file and more examples included! Latest version: 1.0.0.1 Download: TCPServer UDF.rar Changelog 1.0 - First release - 18/04/20151.0.0.1 - Bug fix __TCPServer_Accept internal function / help file recompiled - 26/04/2015Perhaps you will need to uncompress the file first, so the help file will work. Fork this on Github: http://github.com/jesobreira/TCPServerUDF TCPServer UDF.rar1 point