Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/18/2021 in all areas

  1. Gianni

    Cow say

    This "cow" seems funny to me, At this link (https://dodona.ugent.be/en/activities/1605325419/#) a brief rough description of what this script can do (sorry for the laziness, but that description may be fine). You can use the _CowSayWin() function to display a message formatted in a comic along with an ascii art figure in a standalone window, or you can use _String_CowSay() function to format a plain string in a comic along with an ascii art figure and have it returned in a string for your own purposes, you will probably use it in Consolewrite () or whatever ... The script makes use of the _StringSize() function written by @Melba23 (thanks Melba) of the StringSize.au3 udf that you can extract from the zip file located at this link: https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/. You have to save that udf file in the same directory along with this script. It also makes use of the _WinSetClientSize() function written by @KaFu. (thanks kafu) This function is already built into the main script. I hope you have fun #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <WinAPISys.au3> #include <array.au3> #include <String.au3> #include "StringSize.au3" ; <-- https://www.autoitscript.com/forum/topic/114034-stringsize-m23-new-version-16-aug-11/ _Example() Func _Example() SRandom(@SEC) Local $hCowWin, $aMsg = 0 Local $sMessage, $iWidth, $iClipart, $iTextAlig Local $aMessages[] = ["Bottled water companies don’t produce water, they produce plastic bottles.", _ "The greatest glory in living lies not in never falling, but in rising every time we fall.", _ "Your time is limited, so don't waste it living someone else's life. " & _ "Don't be trapped by dogma which is living with the results of other people's thinking.", _ "Insanity is doing the same thing over and over again and expecting different results", _ "The way to get started is to quit talking and begin doing."] For $i = 1 To 6 $sMessage = $aMessages[Random(0, UBound($aMessages) - 1, 1)] $iWidth = Random(21, 90, 1) $iClipart = Random(0, 3, 1) $iTextAlign = 1 ; Random(0, 2, 1) Left and right alignments are a bit ugly. ; they are allowed however if you need them ; ; You can use the _CowSayWin() function to create the "cowsay" message in a window $hCowWin = _CowSayWin($sMessage, $iWidth, $iClipart, $iTextAlign) ; ; or you can use the _String_CowSay() function to get a string of the "cowsay ascii clipart" ; so that you can use it however you like, probably in a Consolewrite () for example ... ConsoleWrite(_String_CowSay($sMessage, $iWidth, $iClipart, $iTextAlign) & @CRLF) While 1 $aMsg = GUIGetMsg($GUI_EVENT_ARRAY) Switch $aMsg[1] Case $hCowWin Switch $aMsg[0] Case -3 ; $GUI_EVENT_CLOSE ExitLoop EndSwitch EndSwitch WEnd GUIDelete(HWnd($hCowWin)) Next EndFunc ;==>_Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CowSayWin ; Description ...: Display a message in a standalone windows formatted in a balloon along with an ascii art figure ; Syntax ........: _CowSayWin($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]]) ; Parameters ....: $sMsg - a string value. The message to display (in a single line without @cr and or @lf) ; $iBoxLen - [optional] an integer value. Default is 21. ; The wanted width of the Box contining the message ; $iShape - [optional] an integer value. Default is 0. ; The index of the ascii art figure to be displayed along with the message. ; Available values are: ; 0 -> a cow ; 1 -> a sandwich-man ; 2 -> the penguin Tux ; 3 -> a hanging monkey ; ..... to be continued (maybe) ; $iAlign - [optional] an integer value. Default is 1. ; How to justify the string within the frame, that is: ; 0 -> left justified ; 1 -> center justified (default) ; 2 -> right justified ; Return values .: The handle of the created window ; Author ........: Gianni Addiego (Chimp) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _CowSayWin($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1) If $iBoxLen < 21 Then $iBoxLen = 21 Local $iSize = 12 Local $iWeight = $FW_NORMAL Local $iAttrib = $GUI_FONTNORMAL Local $sFont = "Courier new" Local $sSay = _String_CowSay($sMsg, $iBoxLen, $iShape, $iAlign) Local $aMsgReturn = _StringSize($sSay, $iSize, $iWeight, $iAttrib, $sFont) Local $iXpos = (@DesktopWidth - $aMsgReturn[2]) / 2 If $iXpos < 0 Then $iXpos = 0 Local $iYpos = (@DesktopHeight - $aMsgReturn[3]) / 2 If $iYpos < 0 Then $iYpos = 0 Local $hCow = GUICreate("Cowsay", -1, -1, $iXpos, $iYpos, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) ;0x94C803C5, 0x00010101) ; , $WS_EX_DLGMODALFRAME) ;0x94C803C5, 0x00010101) ; Style & ExStyle same as msgbox GUISetFont($iSize, $FW_NORMAL, $GUI_FONTNORMAL, $sFont) _WinSetClientSize($hCow, $aMsgReturn[2], $aMsgReturn[3]) GUICtrlCreateLabel($sSay, 0, 0, $aMsgReturn[2], $aMsgReturn[3]) GUISetState(@SW_SHOW, $hCow) #cs While 1 Switch GUIGetMsg() Case -3 ; $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd #ce Return $hCow EndFunc ;==>_CowSayWin ; By kafu ; https://www.autoitscript.com/forum/topic/201524-guicreate-and-wingetclientsize-mismatch/?do=findComment&comment=1446141 Func _WinSetClientSize($hWnd, $iW, $iH) Local $aWinPos = WinGetPos($hWnd) Local $sRect = DllStructCreate("int;int;int;int;") DllStructSetData($sRect, 3, $iW) DllStructSetData($sRect, 4, $iH) _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)) WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2)) EndFunc ;==>_WinSetClientSize ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringToColumn ; Description ...: passing a (long) string and a value, it returns that same string ; formatted in a column as wide as the value (string is split by @CRs). ; Whenever possible, it tries not to break the words but to split ; lines in between two words ; Syntax ........: _StringToColumn($sString[, $x = 21]) ; Parameters ....: $sString - a string value. The string to format ; $iColumnWidth - [optional] an integer value. Default is 21. ; The wanted width of the text column ; Return values .: The string formatted as required ; Author ........: Gianni Addiego (Chimp) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _StringToColumn($sString, $iColumnWidth = 21) If $iColumnWidth < 1 Then $iColumnWidth = 1 Local $iPreviousSplit = 1 Local $i = $iColumnWidth While $i <= StringLen($sString) $iSplitPoint = StringInStr($sString, " ", 0, -1, $i + 1) If $iSplitPoint = 0 Or $iSplitPoint <= $iPreviousSplit Then $iSplitPoint = $i $sString = StringLeft($sString, $iSplitPoint) & @CR & StringMid($sString, $iSplitPoint + 1) $i = $iSplitPoint + 1 Else $sString = StringReplace($sString, $iSplitPoint, @CR) $i = $iSplitPoint EndIf $iPreviousSplit = $iSplitPoint $i += $iColumnWidth WEnd If StringRight($sString, 1) = @CR Then $sString = StringTrimRight($sString, 1) Return $sString EndFunc ;==>_StringToColumn ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringToFrame ; Description ...: places borders only to the left and to the right of the passed string block ; Syntax ........: _StringToFrame($sStr, $iFrameWidth[, $iAlign = 1[, $sV = "|"]]) ; Parameters ....: $sStr - The string to format; multiline string must be splitted by a @cr. ; $iFrameWidth - wanted Width of the frame ; If the desired width is less than the length of the string, the exceeding part is cut off ; If the desired width is wider than the length of the string, spaces are added ; $iAlign - [optional] an integer value. Default is 1. ; The string is justified within the frame based on the value of the $iAlign variable, that is: ; 0 -> left justified ; 1 -> center justified (default) ; 2 -> right justified ; $sV - [optional] a string value. Default is "|". ; This is the character used to draw the two vertical edges ; Return values .: The formatted string ; Author ........: Gianni Addiego (Chimp) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _StringToFrame($sStr, $iFrameWidth, $iAlign = 1, $sV = "|") ; $iAlign: 0=Left; 1=Center; 2=Right If $iFrameWidth < 1 Then $iFrameWidth = 1 Local $a = StringSplit($sStr, @CR, 2) ; 2 = $STR_NOCOUNT For $i = 0 To UBound($a) - 1 Switch $iAlign Case 1 ; Center string $a[$i] = $sV & _StringSetLen(_StringCenter($a[$i], $iFrameWidth), $iFrameWidth) & $sV Case 2 ; Align to right $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth * -1) & $sV Case Else ; otherwise Align to left $a[$i] = $sV & _StringSetLen($a[$i], $iFrameWidth) & $sV EndSwitch Next Return _ArrayToString($a, @CR) EndFunc ;==>_StringToFrame ; passing a string and a value it returns that string with a len as required ; By Gianni Addiego Func _StringSetLen($sString, $iWantedLen = 1, $sFillChr = " ") If $iWantedLen = 0 Then Return "" Local $iLen = StringLen($sString) Local $iKeepLeft = $iWantedLen > 0 ; else keep the right side of the string $iWantedLen = Abs($iWantedLen) If $iLen >= $iWantedLen Then ; reduce the string length If $iKeepLeft Then Return StringLeft($sString, $iWantedLen) Else Return StringRight($sString, $iWantedLen) EndIf Else ; add chars to the string to reach the wanted len If $iKeepLeft Then Return $sString & _StringRepeat($sFillChr, $iWantedLen - $iLen) Else Return _StringRepeat($sFillChr, $iWantedLen - $iLen) & $sString EndIf EndIf EndFunc ;==>_StringSetLen ; place a string in the middle of a given space ; By Gianni Addiego Func _StringCenter($sString, $iSpace) Local $iLen = StringLen($sString) $iHloc = Int($iSpace / 2) - Int($iLen / 2) If $iHloc < 0 Then Return StringMid($sString, Abs($iHloc) + 1, $iSpace) Else Return _StringRepeat(" ", $iHloc) & $sString EndIf EndFunc ;==>_StringCenter ; #FUNCTION# ==================================================================================================================== ; Name ..........: _String_CowSay ; Description ...: Formats a string in a balloon along with an ascii art figure ; Syntax ........: _String_CowSay($sMsg[, $iBoxLen = 21[, $iShape = 0[, $iAlign = 1]]]) ; Parameters ....: $sMsg - a string value. The String to format (in a single line without @cr and or @lf) ; $iBoxLen - [optional] an integer value. Default is 21. ; The wanted width of the Box contining the message ; $iShape - [optional] an integer value. Default is 0. ; The index of the ascii art figure to be displayed along with the message. ; Available values are: ; 0 -> a cow ; 1 -> a sandwich-man ; 2 -> the penguin Tux ; 3 -> a hanging monkey ; ..... to be continued (maybe) ; $iAlign - [optional] an integer value. Default is 1. ; How to justify the string within the frame, that is: ; 0 -> left justified ; 1 -> center justified (default) ; 2 -> right justified ; Return values .: The passed string formatted in the required format. ; Author ........: Gianni Addiego (Chimp) ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _String_CowSay($sMsg, $iBoxLen = 21, $iShape = 0, $iAlign = 1) ; minimum $iBoxLen is 21 If $iBoxLen / 2 = Int($iBoxLen / 2) Then $iBoxLen += 1 If $iBoxLen < 22 Then $x = 0 Else $x = Ceiling(($iBoxLen - 21) / 2) EndIf Local $sS = _StringRepeat(" ", $x), $sT = _StringRepeat("~", $x) Local $sHeader, $sFooter Switch $iShape Case 1 $sHeader = _ $sS & " \|||/" & @CRLF & _ $sS & " (o o)" & @CRLF & _ "," & $sT & "oo0~~~~~~(_)~~~~~~~~~" & $sT & "," & @CRLF ; header $sFooter = _ "'" & $sT & "~~~~~~~~~~~~~~~~~~oo0" & $sT & "'" & @CRLF & _ ; footer $sS & " |__|__|" & @CRLF & _ $sS & " || ||" & @CRLF & _ $sS & " oo0 0oo" Case 2 $sHeader = _ "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header $sFooter = _ "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _ " \ .--." & @CRLF & _ " \ |o_o |" & @CRLF & _ " |:_/ |" & @CRLF & _ " // \ \" & @CRLF & _ " (| | )" & @CRLF & _ " /'\_ _/`\" & @CRLF & _ " \___)=(___/" Case 3 $sHeader = _ "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header $sFooter = _ "'" & $sT & "oo0~~~~~~~~~~~~~~~0oo" & $sT & "'" & @CRLF & _ ; footer $sS & " \\ //" & @CRLF & _ $sS & " > \ \\|||// / <" & @CRLF & _ $sS & " > \ _ _ / <" & @CRLF & _ $sS & " > \ / \ / \ / <" & @CRLF & _ $sS & " > \\_o_o_// <" & @CRLF & _ $sS & " > ( (_) ) <" & @CRLF & _ $sS & " >| |<" & @CRLF & _ $sS & " / |\___/| \" & @CRLF & _ $sS & " / (_____) \" & @CRLF & _ $sS & " / o \" & @CRLF & _ $sS & " ) ___ (" & @CRLF & _ $sS & " / / \ \" & @CRLF & _ $sS & " ( / \ )" & @CRLF & _ $sS & " >< ><" & @CRLF & _ $sS & " ///\ /\\\" & @CRLF & _ $sS & " ''' '''" Case Else $sHeader = _ "," & $sT & "~~~~~~~~~~~~~~~~~~~~~" & $sT & "," & @CRLF ; header $sFooter = _ "'~~~~~~~~~~~~~~~~~~~~~" & $sT & $sT & "'" & @CRLF & _ " \ ^__^" & @CRLF & _ " \ (oo)\_______" & @CRLF & _ " (__)\ )\/\" & @CRLF & _ " ||----w |" & @CRLF & _ " || ||" EndSwitch Return $sHeader & _StringToFrame(_StringToColumn($sMsg, $iBoxLen), $iBoxLen, $iAlign) & @CRLF & $sFooter EndFunc ;==>_String_CowSay
    1 point
  2. ..actually, uBlock origin in the browser. Most viruses are distributed via web sites, so, a good popup blocker should be all that's need most times.
    1 point
  3. See discussion in sticky above
    1 point
  4. ...and I guess the destination folder ?. I don't use antiviruses. I use wetware but is proprietary
    1 point
  5. Nine

    Dynamic Variables from an Array

    Unless you have Ave. or Ave, and having a loop to search for every possibilities will be costly (compare to the 1 liner SRE).
    1 point
  6. https://www.autoitscript.com/autoit3/docs/functions/PixelGetColor.htm And I would suggest you read the forum rules and the help file and then make a small piece of code on what you try to achieve then people will jump in on helping you.
    1 point
  7. Nine

    Dynamic Variables from an Array

    Using StringInStr can be misleading as you can search for AVE for example and the address can contain AVE somewhere else like 123 Maverick Road.... I think SRE would be more appropriate to perform a more robust search : #include <Array.au3> ;Local $sList = StringReplace(FileRead("Text.txt"),@CRLF, "|") Local $sList = "ALY|AVE|BCH|BLVD" ; for testing purpose Local $sAdr = "1234 London Square Ave Suite 1234566" Local $aExt = StringRegExp($sAdr, "(?i)\b(" & $sList & ")\b\h(.*)", 1) _ArrayDisplay($aExt)
    1 point
  8. @PnD StringSplit() returns a 1-Dimensional array, as stated in the help file, so you don't need to specify any other dimension. Just loop through the array with $i and you'd be able to achieve what you're trying to
    1 point
  9. If at all possible, compile your exe's as 64-bit. This trick no longer works in AutoIt v3.3.16.0 When compiled as 32-Bit, I get as many as 12-18 virus detections from VirusTotal. The exact same script, compiled as 64-Bit, only has 2-3 detections. Almost all Windows computer systems these days are 64-Bit operating systems. Take NOTICE: special considerations are required for the Windows Registry, Windows\System* files and ProgramFiles* directories.
    1 point
  10. This is a continuation of Custom drawn TreeViews and ListViews. However, only with respect to listviews. The crucial difference between the new and the old code is that the new code is a complete UDF and therefore much easier to use. Because the UDF is about colors and fonts in listview items and subitems, it's only for listviews in Details or Report view. Main features The UDF supports the following main features. Colors and fonts: 1 Single items/subitems Back colors Fore colors Fonts and styles 2 Colors/fonts for entire columns 3 Alternating colors (entire listview) Alternating colors for rows, columns or both Both default and alternating color can be set Number of rows/columns between color change can be set 4 Custom default colors/font instead of standard default colors/font Custom default back and fore colors can be set for Normal listview items (instead of white and black) Selected listview items (instead of dark blue and white) Unfocused selected items (instead of button face and black) 5 Colors for selected listview items Back and fore colors for selected items when listview has focus Back and fore colors for selected items when listview has not focus Features 1, 2 and 3 cannot be mixed together. 4 and 5 can be mixed with the previous features. 5 extends the functionality of the previous features by adding colors to selected items. 5 cannot be used alone. Listviews: Multiple listviews Native and non-native listviews Native and non-native listview items The UDF can be used with existing listviews WM_NOTIFY message handlers: WM_NOTIFY message handlers can be used completely as usual The UDF can be used with existing WM_NOTIFY message handlers Colors and fonts for single listview items/subitems are stored in an array. The index in this array for a given listview item is stored in ItemParam. Except for this usage of ItemParam nothing in the UDF assumes that listviews or items/subitems are created in a certain way, or that any WM_NOTIFY handlers exists or are designed in a certain way. It should be easy to use the UDF with existing listviews with or without a WM_NOTIFY message handler or other message handlers. WM_NOTIFY message handlers Colors and fonts in listviews are implemented through custom draw notifications in the form of WM_NOTIFY messages. A WM_NOTIFY message handler is needed to implement colors/fonts. If a listview is included in a GUI and a little more than just very basic functionality is wanted, another WM_NOTIFY handler is soon needed to implement this functionality. To register a WM_NOTIFY handler you use the function GUIRegisterMsg. This function can register only one message handler at a time for the same message type. The result of code like this is that only WM_NOTIFY2 message handler is working: GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY1" ) ; Register WM_NOTIFY1 GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY2" ) ; Register WM_NOTIFY2 (unregisters WM_NOTIFY1) This makes it difficult to implement colors/fonts in a UDF, if you at the same time want to implement advanced functionality in your own code. A solution is to register the WM_NOTIFY message handler, that takes care of custom draw notifications, in a different way. This can be done by a technique called subclassing, which is implemented through the four functions SetWindowSubclass, GetWindowSubclass, RemoveWindowSubclass and DefSubclassProc (coded in WinAPIShellEx.au3). Subclassing Subclassing a window (or control) means to create a message handler for the window, that will receive messages to the window before the original message handler for the window. This section is information on the implementation of a WM_NOTIFY message handler through subclassing: The UDF The UDF is implemented in UDFs\ListViewColorsFonts.au3. This is a list of the most important functions copied from the UDF (around line 200): ; Initiating and exiting ; ---------------------- ; ListViewColorsFonts_Init ; ListViewColorsFonts_Exit ; ; Set colors/fonts for items/subitems ; ----------------------------------- ; ListViewColorsFonts_SetItemColors ; ListViewColorsFonts_SetItemFonts ; ListViewColorsFonts_SetItemColorsFonts ; ; Set colors/fonts for entire listview ; ------------------------------------ ; ListViewColorsFonts_SetColumnColorsFonts ; ListViewColorsFonts_SetAlternatingColors ; ListViewColorsFonts_SetDefaultColorsFonts ; ; Maintenance functions ; --------------------- ; ListViewColorsFonts_Redraw Some of the functions in the complete list in the file are not coded in this version. To use the UDF you first calls ListViewColorsFonts_Init which stores information about the listview and the parent window, and creates the subclass that takes care of the actual drawing of the colors and fonts. Then you call one or more of the ListViewColorsFonts_Set-functions to define the colors and fonts. Depending on the functions you might also need to call ListViewColorsFonts_Redraw. And that's all. Finally you can call ListViewColorsFonts_Exit to remove the subclass before the script exits. If you don't call ListViewColorsFonts_Exit it's called automatically by the UDF. This is the syntax for ListViewColorsFonts_Init and the information about $fColorsFonts flag also copied from ListViewColorsFonts.au3: ; ListViewColorsFonts_Init( $idListView, $fColorsFonts = 7, $iAddRows = 100, $bNative = False ) ; $idListView - Listview control ID or handle ; $fColorsFonts - Specifies options for usage of colors and fonts in the listview. Add required options together. ; 1: Back colors for items/subitems ; Can not be specified separately in this version ; 2: Fore colors for items/subitems ; Can not be specified separately in this version ; 4: Fonts and styles for items/subitems ; Can not be specified separately in this version ; 7: Back and fore colors, fonts and styles ; Flags 1/2/4 are combined in flag 7 in this version ; ; 8: Colors/fonts for entire columns ; ; 16: Alternating row colors (for entire listview) ; 32: Alternating column colors (for entire listview) ; ; 64: Custom default colors and font (for entire listview) ; Custom default back and fore colors can be set for ; - Normal listview items (instead of white and black) ; - Selected listview items (instead of dark blue and white) ; - Unfocused selected listview items (instead of button face and black) ; ; 128: Colors for selected items when listview has focus ; 256: Colors for selected items when listview has not focus The limitations with respect to flags 1, 2 and 4 in this version is only a matter of optimizations. It has nothing to do with features. Drawing of selected items is largely controlled by Windows. A lot of extra code is needed to implement custom colors for selected items through flags 128 and 256. For $fColorsFonts flag is further noted that: ; - Flags 1/2/4 can be combined in a total of seven different ways ; - Flags 1/2/4 (items/subitems), flag 8 (columns) and flags 16/32 (listview) cannot be combined ; - Flag 64 is used to replace the standard default colors/font by custom default colors/font ; Flag 64 can be used alone or in combination with flags 1-32 ; Custom default colors/font must be set before all other colors/fonts ; Flag 64 leads to some restrictions on the features for items/subitems (flags 1/2/4) ; - Flags 128/256 extends the functionality of flags 1-64 by adding colors to selected items ; Flags 128/256 cannot be used alone An array $aListViewColorsFontsInfo is used to store information about the listview, the parent window and the usage of colors/fonts in the listview. For flags 1/2/4 about single items/subitems another array $aListViewColorsFonts is used to store the colors and fonts for the items and subitems. The number of columns in this array depends on whether the flags 128/256 are set or not. The first 160 lines in the UDF contains information about these arrays. For flags 1/2/4 ItemParam field in the listview is used to store the zero based row index in $aListViewColorsFonts for a given listview item. For native listview items created with GUICtrlCreateListViewItem the existing value of ItemParam (control ID) is used as index in an intermediate array $aListViewColorsFonts_Index, and $aListViewColorsFonts_Index holds the index in $aListViewColorsFonts stored as index+1. For non-native listview items the index in $aListViewColorsFonts is stored in ItemParam as -index-20. For non-native listview items an existing value of ItemParam is overwritten. The best way to add colors and fonts to listviews is to put each listview in its own child window. The child window should not contain any other controls, and it should have the same size as the listview. However, this is not a requirement. See the UDF for documentation of the other functions. The implementation of the functions starts in line 230 and onwards. The UDF also contains a group of internal functions. Among other the subclass callback functions to draw the colors and fonts in response to NM_CUSTOMDRAW notifications from the listview. So far the UDF contains seven callback functions which starts around line 2100 and runs over the next 1300 lines nearly to the bottom of the file. The code This section is about some code details related partly to the subclass callback functions and partly to drawing of selected items. Subclass callback functions: Drawing of selected items: In the current version of the UDF the callback function that is implemented to draw single items/subitems ($fColorsFonts = 1/2/4) is the function that can handle all features ($fColorsFonts = 1+2+4 = 7). If only a part of the features is needed, it's possible to create smaller and faster functions, which only implements this part of the features. These functions (six functions in total) are postponed to next version. Features A few comments on the features. The main features in terms of colors and fonts are (a repeat of the list in top of post): 1 Single items/subitems 2 Colors/fonts for entire columns 3 Alternating colors (entire listview) 4 Custom default colors/font instead of standard default colors/font 5 Colors for selected listview items 1, 2 and 3 are features for different kind of elements in the listview and cannot be mixed together. 4 can be used either as an independent feature or mixed with 1, 2 or 3. 5 cannot be used as an independent feature but can only be used together with 1, 2, 3 or 4. 5 extends the functionality of these features by adding colors to selected items. When features 1, 4 and 5 are mixed together, it may look as shown in the following illustrations (screen dumps of examples 3.1 and 4.1 in folder \Examples\5) Selected items\). The first illustration shows how it looks when colors for single items/subitems are mixed with colors for selected items: In the upper picture rows 3-6 are provided with back and fore colors. All subitems in row 3 and 4. Only a few subitems in row 5 and 6. The rows are normal (unselected) rows. In the middle picture rows 2-7 are selected and the listview has focus. Rows 3-6 are also provided with back and fore colors for selected items. In the lower picture rows 2-7 are selected but the listview has not focus. Rows 3-6 are also provided with back and fore colors for selected but unfocused items. In the second illustration the standard default colors are replace with custom default colors. The standard default back and fore colors are: Normal (unselected) items: White and black Selected items in focused listview: Dark blue and white Selected items in unfocused listview: Button face and black These custom default colors are used in the illustration: Normal (unselected) items: Light green and brown Selected items in focused listview: Shiny green (chartreuse) and black Selected items in unfocused listview: Dark green and black Examples Two folders with examples is included in the zip below. The first folder is named Examples and contains examples about the usage of the functions in the UDF. The second folder is named UDF topics and contains examples related to the implementation of the UDF. It's about the use of the subclassing technique as a substitute for a WM_NOTIFY message handler. Particularly about the message flow and performance issues. These examples are addressed in next section. The Examples folder contains these subfolders and files: 0) UDF examples\ - The small examples from the documentation of the functions in the UDF 1) Items-subitems\ - Colors and fonts for single items/subitems 2) Entire columns\ - Colors and fonts for entire columns 3) Alternating colors\ - Alternating row/column colors in an entire listview 4) Custom defaults\ - Replace standard default colors/font with custom defaults 5) Selected items\ - Colors for selected items when listview has focus and has not focus 6) Help file examples\ - Shows how to add colors to a few examples from AutoIt Help file 7) Original examples\ - An implementation of the examples in the old thread with this UDF Listview templates\ - A collection of listview templates ready to add colors/fonts Features demo.au3 - A brief demonstration of all features No colors or fonts.au3 - Reference example All examples runs on Windows XP and later without any performance issues. Folder 1 - 5 demonstrates the five main color/font features listed in top of post. In most of the subfolders you can find a _Readme.txt file with a brief description of the examples. Multiple selections is enabled in most listviews. A few examples will not pass an Au3Check. In particular the examples in subfolder 1 and 2 and the examples in UDF topics folder (see next section) were used to test the subclassing technique as a substitute for a WM_NOTIFY message handler. More information about some of the examples: Examples\0) UDF examples\0) ListViewColorsFonts_Init\Example 1.au3: #include <GUIConstantsEx.au3> #include "..\..\..\UDFs\ListViewColorsFonts.au3" #include "..\..\..\UDFs\GuiListViewEx.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create GUI Local $hGui = GUICreate( "ListViewColorsFonts_Init\Example 1", 420, 200, -1, -1, $GUI_SS_DEFAULT_GUI-$WS_MINIMIZEBOX ) ; Create ListView Local $idListView = GUICtrlCreateListView( "", 10, 10, 400, 180, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL, $WS_EX_CLIENTEDGE ) _GUICtrlListView_SetExtendedListViewStyle( $idListView, $LVS_EX_DOUBLEBUFFER+$LVS_EX_FULLROWSELECT ) Local $hListView = GUICtrlGetHandle( $idListView ) ; Reduces flicker ; Add columns to ListView _GUICtrlListView_AddColumn( $idListView, "Column 1", 94 ) _GUICtrlListView_AddColumn( $idListView, "Column 2", 94 ) _GUICtrlListView_AddColumn( $idListView, "Column 3", 94 ) _GUICtrlListView_AddColumn( $idListView, "Column 4", 94 ) ; Fill ListView Local $iItems = 100 For $i = 0 To $iItems - 1 GUICtrlCreateListViewItem( $i & "/Column 1|" & $i & "/Column 2|" & $i & "/Column 3|" & $i & "/Column 4", $idListView ) Next ; Perform initializations to add colors/fonts to single items/subitems ListViewColorsFonts_Init( $idListView, 7 ) ; $fColorsFonts = 7, ( $iAddRows = 100, $bNative = False ) ; Set a green back color for an entire item and a yellow back color for a single cell ListViewColorsFonts_SetItemColors( $idListView, 3, -1, 0xCCFFCC ) ; Green back color for entire item ListViewColorsFonts_SetItemColors( $idListView, 3, 2, 0xFFFFCC ) ; Yellow back color for cell 2 in item ; Force an update of local variables in drawing function ListViewColorsFonts_Redraw( $idListView ) ; Adjust height of GUI and ListView to fit ten rows Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows( $hListView, 10 ) WinMove( $hGui, "", Default, Default, Default, WinGetPos( $hGui )[3] - WinGetClientSize( $hGui )[1] + $iLvHeight + 20 ) WinMove( $hListView, "", Default, Default, Default, $iLvHeight ) ; Show GUI GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Delete color/font info for listview ListViewColorsFonts_Exit( $idListView ) GUIDelete() EndFunc UDF topics The examples in UDF topics folder is about the use of subclassing as a substitute for a WM_NOTIFY message handler. Particularly about the message flow and performance issues. These examples illustrates some of the issues, that was discussed in the Subclassing section above, with code. The UDF topics folder contains these subfolders: 1) Subclassing\ - Creating listviews in GUI or child windows? 2) Performance\ - How many listviews can you create in GUI? More information about the examples: Next version In The code section above is already mentioned a number of subclass callback functions which are postponed to next version. The purpose of these additional functions is merely to optimize the code in terms of speed. A number of ListViewColorsFonts_Get-functions to complement the corresponding ListViewColorsFonts_Set-functions are also deferred to next version. For single items/subitems ($fColorsFonts = 1/2/4) colors and fonts are stored in $aListViewColorsFonts array which again is stored in $aListViewColorsFontsInfo. The three functions ListViewColorsFonts_SetItemColors / SetItemFonts / SetItemColorsFonts are used to update $aListViewColorsFonts item by item or subitem by subitem. It would be much faster to update $aListViewColorsFonts directly. Two functions are needed to get a copy of the array from $aListViewColorsFontsInfo and store the array again after the updates. And there is also a need for a couple of examples to illustrate the technique. Examples to dynamically update colors and fonts are missing in this version. Perhaps there is also a need for a few functions to support dynamically updates. For non-native listviews created with _GUICtrlListView_Create it's not uncommon to use ItemParam to store a user defined value. If index in $aListViewColorsFonts is stored in ItemParam, it's no longer possible to use ItemParam for such purposes. A couple of functions to give the user an opportunity to still be able to store a user defined value would be nice. Several global variables are defined in this version. They will be removed in the next version except for a few variables which probably will need to be global in performance terms. If there will be reported any issues or problems in this version, they of course also need to be addressed. The next version should be ready in 2-3 months, and it should also be the final version. Zip file The zip is structured in this way Examples\ UDF topics\ UDFs\ ListViewColorsFonts.au3 GuiImageListEx.au3 GuiListViewEx.au3 NamedColors.au3 OtherColors.au3 NamedColors.au3 contains global constants of named colors copied from .NET Framework Colors Class. You need AutoIt 3.3.10 or later. Tested on Windows 7 32/64 bit and Windows XP 32 bit. Comments are welcome. Let me know if there are any issues. (Set tab width = 2 in SciTE to line up comments by column.) ListViewColorsFonts.7z
    1 point
×
×
  • Create New...