Popular Post LarsJ Posted March 20, 2016 Popular Post Share Posted March 20, 2016 (edited) 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: Spoiler Subclassing is about Windows messages. The purpose of subclassing is to capture messages to a window or control before they are received by the original receiver. In that way we can respond to messages with our own code instead of the default code. In this case, we can respond to custom draw notifications for the listview by drawing our own colors instead of the default white and black back and fore colors. Because we only handles custom draw notifications, all other notifications and messages must be forwarded to the original receiver. What are we going to subclass? We are going to subclass the window or control that receives the WM_NOTIFY messages that contains the custom draw notifications. These messages are sent by the code in ComCtl32.dll and by the operating system. The messages are not sent to the listview, but to the parent window of the listview. Creating a subclass To create a subclass we use the function _WinAPI_SetWindowSubclass. The first parameter in this function is the handle for the window or control we are going to subclass. The second parameter is a pointer to the subclass callback function. The subclass callback function is simply a message handler. The procedure for implementing a subclass (message handler) based on _WinAPI_SetWindowSubclass is very similar to the procedure for implementing a message handler created with GUIRegisterMsg. See post 27 of the thread named "How to use all messages in GuiGetMsg()" in "AutoIt General Help and Support" forum for a simple example. Message flow The message flow when subclassing is implemented is shown schematically in this picture: WM_MESSAGEs from Windows OS is generated in DLL-files in response to user actions in the GUI. For example WM_MOUSEMOVE messages when the user moves the mouse across the GUI from one control to another. A lot of WM_MOUSEMOVE messages. The code in DLL-files is compiled C++ code. This is very fast code. The code can easily generate all the messages. The messages are sent to the internal AutoIt message handler. The code in this message handler is also compiled C++ code. The code can easily handle all the messages. When subclassing is implemented the subclass callback function (message handler) is called after WM_MESSAGEs are sent from Windows OS but before they are received by the internal AutoIt message handler. In the picture it's a WM_NOTIFY message handler to handle NM_CUSTOMDRAW notifications from listviews. Performance issue Note the point in the message flow where the subclass callback function is inserted. If you implement subclassing in your code, the callback message handler is always inserted at this point in the message flow. The code in this message handler is AutoIt code. Compared to compiled C++ code AutoIt code is a little slow. In a very round number about 1,000 times slower. Inserting AutoIt code at that point of the message flow is a very potential bottleneck. This is the most important thing to remember if you implement subclassing in your code. Subclassing the GUI or a child window? We found out above that to get WM_NOTIFY messages from a listview we had to subclass the parent window of the listview. The parent of a listview is usually an AutoIt GUI. Subclassing an entire GUI is not a good idea. If it's a complete GUI with a main menu, a toolbar, a status bar and several controls, a tremendous number of Windows messages are sent to the GUI. If we subclass the GUI, the subclass callback function (message handler) will be called for all these messages. We are only interested in messages related to the listview. If we put the listview in a child window, it's enough to subclass the child window, and we'll only receive messages related to the listview. Multiple listviews A UDF should be able to handle multiple listviews. How do we separate messages from different listviews in relation to subclassing? Of course we can test that it's the right listview handle in the subclass callback function. Because this is about custom drawn listview items, which generates a lot of custom draw notifications, a test of all these messages against 3, 4, 5 or more listview handles can be a problem in itself. It seems to be a better idea to separate messages from different listviews in advance. Again the answer is child windows. If we put each listview in its own child window, the messages from a specific listview will only be sent to the corresponding child window. Then we just have to subclass each child window. Fortunately, we can use the same subclass callback function for all child windows. Design choiceIn this UDF it's decided to handle multiple listviews by creating a subclass (with _WinAPI_SetWindowSubclass) for each listview. This works really well if each listview is placed in its own child window or if a few listviews are grouped together in child windows. If multiple listviews are located directly in the main GUI window, and the GUI is subclassed with a callback function for each listview, a message from one listview to the parent window (the GUI) will be forwarded to all callback functions. Not just the callback function that corresponds to the listview. If the number of listviews is increased, this will sooner or later be a performance problem. If performance becomes a problem, the solution is to place one or more or all listviews in child windows. The pictures below illustrates the message flow when listviews are located directly in the main GUI window, and when listviews are placed in child windows. Listviews located in main GUI If a message from listview 1 is sent to the parent window (the GUI), the message is forwarded to all three callback functions, and not just callback function 1 which corresponds to listview 1. Callback functions 2 and 3 are not doing anything because it's the wrong listview (determined from listview handle in the WM_NOTIFY message), but the functions are still called, and code is performed to determine the listview. When it's determined, that it's the wrong listview, the code returns. Similar for the two other listviews. If a message from a button is sent to the parent window, this message is also forwarded to all three callback functions. This is a consequence of the three callback functions defined for the same window (the GUI). A message from a button is uninteresting for the callback functions which only deals with listviews. If there are many listviews and many controls, the callback functions will be called extremely many times. And in most cases, they are not doing anything. Listviews placed in child windows If each listview is placed in its own child window a message from a listview is sent only to the corresponding callback function. A message from a button is not forwarded to any callback functions at all. 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, because messages from these controls would be forwarded to the callback function. The child window should have the same size as the listview. This ensures that for example WM_MOUSEMOVE messages are forwarded to the callback function only if the mouse is inside the listview. However, it's not a requirement, that each listview is placed in its own child window. But this will give the best performance if there are many listviews and many controls. For a smaller number of listviews all listviews can be placed in the same child window. Then messages from the listviews are separated from messages from other controls. Return values? Custom draw notifications are handled by the subclass callback function. Because there are so many of these notifications, we don't want them to be forwarded to a user defined WM_NOTIFY message handler. They are already handled by the callback function. To avoid that the notifications are forwarded, we'll make sure to return one of the valid custom draw return values in each of the different custom draw stages in the callback function. In this way the code returns from the function before it reaches the last line where the notifications are forwarded. This is shown in the first picture above. When it's verified that it's a WM_NOTIFY message for the current listview, and it contains a NM_CUSTOMDRAW notification, the custom draw code is executed, but the WM_NOTIFY message is not forwarded to the internal AutoIt message handler. 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: Spoiler Subclassing the listviews (more precisely the parent windows of the listviews) is done in the bottom of ListViewColorsFonts_Init function. To handle multiple listviews the following design choice is made: In this UDF it's decided to handle multiple listviews by creating a subclass (with _WinAPI_SetWindowSubclass) for each listview. This is the code that subclasses a listview: _WinAPI_SetWindowSubclass( _ $hParent, _ ; Handle to listview parent window $pListViewColorsFontsSC_Columns, _ ; Pointer to subclass callback (SC) function $iIndex, _ ; $iSubclassId = $iIndex, index in $aListViewColorsFontsInfo array $hListView ) ; $pData = $hListView, listview handle The first two parameters of _WinAPI_SetWindowSubclass is the handle of the window being subclassed and the pointer to the subclass callback function. The subclass callback function ListViewColorsFontsSC_Columns is simply a message handler that handles NM_CUSTOMDRAW notifications included in WM_NOTIFY messages. The function is registered with DllCallbackRegister and the pointer is created with DllCallbackGetPtr. ListViewColorsFontsSC_Columns is used to add colors/fonts to entire listview columns. The third parameter is $iSubclassId. This parameter is set to $iIndex which is the index in $aListViewColorsFontsInfo array that contains information about the listviews. This index is of course unique for a given listview. If a GUI contains multiple listviews with column colors/fonts they all use the same callback function ListViewColorsFontsSC_Columns and the same pointer $pListViewColorsFontsSC_Columns. $iSubclassId = $iIndex garanties that the subclasses are unique (a unique combination of the function pointer and $iSubclassId creates a unique subclass). The last parameter $pData is set to $hListView, the listview handle. The parameters $iSubclassId and $pData are both passed to the subclass callback function: ListViewColorsFontsSC_Columns( _ $hWnd, $iMsg, $wParam, $lParam, _ $iIndex, _ ; $iSubclassId = $iIndex, index in $aListViewColorsFontsInfo array $hListView ) ; $pData = $hListView, listview handle The first four parameters are the usual parameters which are also used in a message handler created with GUIRegisterMsg. Fifth and sixth parameter is $iSubclassId = $iIndex and $pData = $hListView. Because $iSubclassId = $iIndex is the index in $aListViewColorsFontsInfo array, this parameter can simply be used to switch listview information each time colors/fonts are going to be drawn for a new listview. This is done in an If-statement in top of the callback function: If $iIndexPrev <> $iIndex Then ; $iIndex is used to switch between different listviews $iIndexPrev = $iIndex ; $iIndex <= 0 is used to force a re- If $iIndex <= 0 Then Return ; read of $aListViewColorsFontsInfo. $idListView = $aListViewColorsFontsInfo[$iIndex][0] ; Listview control ID $bImages = $aListViewColorsFontsInfo[$iIndex][3] ; Subitem images $bChkboxes = $aListViewColorsFontsInfo[$iIndex][4] ; Checkboxes $hGui = $aListViewColorsFontsInfo[$iIndex][6] ; Main GUI window handle $sClassNN = $aListViewColorsFontsInfo[$iIndex][7] ; CLASSNN listview name $fSelected = $aListViewColorsFontsInfo[$iIndex][15] ; Flag for selected items $aDefaults = $aListViewColorsFontsInfo[$iIndex][17] ; Current default colors and font $aColorsFonts = $aListViewColorsFontsInfo[$iIndex][22] ; Array with color/font info, $iSubItem is row index $iColorsFonts = $aListViewColorsFontsInfo[$iIndex][23] ; Number of used rows in array $bNotSelected = $fSelected ? False : True ; Convert to boolean $iImgWidth0 = 0 EndIf $iIndexPrev and the variables which holds array information are static locals in the function. $iMsg is the Windows message code (WM_MESSAGE). If $iMsg is a WM_NOTIFY message then $lParam is a pointer to a $tagNMHDR structure which contains information about the WM_NOTIFY message. One field in this structure is "hWndFrom" which is the handle of the listview that the message belongs to. Because $pData = $hListView (the sixth function parameter) is the listview handle for the listview that this subclass belongs to, it's easy to check if a WM_NOTIFY message is relevant for this listview. This is the case if hWndFrom = $hListView and the message is handled. If not the message is immediately forwarded. The very first line in each callback function looks like this: If $iMsg <> $WM_NOTIFY Or _ $hListView <> HWnd( DllStructGetData( DllStructCreate( $tagNMHDR, $lParam ), "hWndFrom" ) ) Then _ Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] This line forwards both irrelevant messages (not WM_NOTIFY messages) and messages form irrelevant listviews (not $hListView). Especially if a parent window (usually the GUI) contains multiple listviews, this line is very efficient. Drawing of selected items: Spoiler To draw a listview item or subitem with a custom back and fore color you normally just fill out the ClrTextBk and ClrText members of the $tagNMLVCUSTOMDRAW structure in either the item or subitem prepaint stage of the drawing cycle. And that's all. The prepaint stage is before any default drawing of the item/subitem which takes care of the actual drawing of the item/subitem with the colors you have specified. The default drawing also takes care of drawing a checkbox, an icon or a subicon (subitem icon). The default drawing is performed by code in ComCtl32.dll. The default drawing code also draws selected items with the dark blue and white back and fore color in a focused listview, and the button face and black back and fore color in an unfocused listview. Finally the default drawing code draws the dotted rectangle around the focused item. Because the colors for selected items is largely controlled by Windows, the ClrTextBk and ClrText fields are ignored for these items. The only way to use custom colors for selected items is to draw these items in the postpaint stage of the drawing cycle. This is after the default drawing. This means that you have to draw the back and fore color manually with GDI-functions. Furthermore, you must make sure not to delete any of the default drawing, that you still need. This includes a checkbox, an icon, subicons and the dotted rectangle around focused item. Drawing of selected items requires significantly more code than drawing of normal unselected items. The five callback functions which are used to draw column colors ($fColorsFonts = 8), alternating colors ($fColorsFonts = 16/32/48) and custom default colors ($fColorsFonts = 64) can all be optimized by splitting each of the functions up in two functions: One to handle normal unselected items (when the values 128/256 for selected items is not included in $fColorsFonts flag) and one to handle selected items (when one of the values 128/256 for selected items is included in $fColorsFonts flag). The versions of the functions which are included in the current UDF are the latter functions which can handle selected items. The smaller and faster functions which can only handle normal items are postponed to next version. 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: Spoiler Features demo The GUI consists of 6 pages with 2-4 tabs. This is the main topics: Page 1: Items and subitems, $fColorsFonts = 7 Page 2: Checkboxes and icons, $fColorsFonts = 7 Page 3: A few items/subitems, $fColorsFonts = 7+64+256 Page 4: Column colors, $fColorsFonts = 8+64+256 Page 5: Alternating colors, $fColorsFonts = 16+64+256, 32+64+256, 48+64+256 Page 6: Custom default colors, $fColorsFonts = 64+256 It's advantageous to review page 6 before page 3, 4 and 5. Because the height of listview items is very small on Windows XP compared to later Windows versions, there is a rather large empty area between the listview and the Prev/Next buttons on Windows XP. Page 3 is about a few colored items/subitems. It demonstrates how colors can be set for normal (unselected) items, for selected items when listview has focus, and for selected items when listview has not focus. This is a short review of the tabs and controls on page 3. Click tab 3 "Selected items" and click the second checkbox. This sets a checkmark in both checkboxes and enables colors for selected items. Click tab 1 "A few items/subitems". Click the three checkboxes one by one in proper order and watch the listview. When there is a checkmark in all three checkboxes the colors for normal, selected and unfocused listview items can be verified by clicking the buttons. It should look as shown in the picture: Click tab 2 "Custom default colors". Click the three checkboxes one by one in proper order and watch the listview. When there is a checkmark in all three checkboxes the custom default colors for normal, selected and unfocused listview items can be verified by clicking the buttons. It should look as shown in the picture: The checkboxes on tabs 1 and 2: Click the last checkbox to set a checkmark in all checkboxes at once. Click the first checkbox to clear all checkmarks at once. On pages 4 and 5 all controls are reset when you switch between tabs 1 and 2 (because it's different listviews). Test tabs 1, 3, 4 at a time and tabs 2, 3, 4 at a time. You can search for "Page \d Tab 0" (regular expression) to find the corresponding code sections in "Features demo.au3". Start searching around line 1100. 1) Items-subitems The examples are about colors and fonts in normal (unselected) items/subitems. The folder contains 9 scripts. The first six scripts all creates 4 listviews and demonstrates different ways to create listviews directly in GUI and in child windows. The six scripts are numbered after performance. 1 is best. 6 is worst. In relation to the UDF listviews in child windows and non-native listview items are most efficient. The scripts contains "GUI" or "Childs" as part of the file name to indicate whether the listviews are located directly in GUI or in child windows. The scripts contains "Native" or "Non-native" as part of the file name to indicate whether the listview items are treated as native or non-native listview items. The examples contains a WM_NOTIFY message handler created with GUIRegisterMsg to catch double click and Enter key in listviews. 2) Entire columns Colors and fonts in entire columns. Normal (unselected) items. 4 listviews, 1000 rows, 4 columns. Give the scripts a second to start up. The "8 listviews" folder contains the same two scripts but with 8 listviews instead of 4. 8 listviews is a sufficiently high number for the subclassing technique to start affect performance in script 1, where all listviews are created directly in GUI. Especially on a not too fast PC. You can test performance of the listviews and the impact of subclassing by dragging the scrollbar with the mouse. A declining performance can be seen in the emergence of elastic between the mouse pointer and the scrollbar. The more elastic the worse the performance. The first listview in upper left corner seems to suffer most of the subclassing. There is no performance impact in script 2, where each listview is created in its own child window. Examples\0) UDF examples\0) ListViewColorsFonts_Init\Example 1.au3: expandcollapse popup#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: Spoiler 1) Subclassing This folder contains two scripts: "Custom draw, GUI.au3" and "Custom draw, Childs.au3". The code in these scripts is exactly the same code as shown in post 37 and 38 of the thread named "How to use all messages in GuiGetMsg()" in "AutoIt General Help and Support" forum. I'll refer to these posts for information about the two scripts. Post 36 of that thread is more or less a repetition of the Subclassing section above. 2) Performance The scripts in this folder creates a GUI with room for 16, 24 and 32 listviews. 4 listviews are created automatically when the scripts starts up. "Multiple listviews, Childs.au3" and "Multiple listviews, GUI.au3" contains functions to create the listviews. The scripts contains "GUI" or "Childs" as part of the file name to indicate whether the listviews are located directly in GUI or in child windows. If you right click the GUI you can add 4 listviews at a time. Then you can test how many listviews you can add before the performance becomes too bad. You can test the performance of the listviews and the impact of subclassing by dragging the scrollbar with the mouse. A declining performance can be seen in the emergence of elastic between the mouse pointer and the scrollbar. The more elastic the worse the performance. The first listviews in upper left corner seems to suffer most of the subclassing. And especially the "Column colors" listview because the rows have to be drawn subitem by subitem. For the "GUI" scripts the performance impact of subclassing is also clearly seen on creation of the listviews and on deletion of the GUI. Note that the performance issues related to subclassing are only relevant for the "GUI" scripts. There are no performance issues for the "Childs" scripts. 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 Edited March 12, 2018 by LarsJ New image links pixelsearch, Gianni, Danyfirex and 13 others 13 3 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
nend Posted March 20, 2016 Share Posted March 20, 2016 Very nice, I will keep this in my snippets directory. Thanks!! Link to comment Share on other sites More sharing options...
Danyfirex Posted March 20, 2016 Share Posted March 20, 2016 Nice LarsJ. Working great over Windows 10 x64. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mLipok Posted March 20, 2016 Share Posted March 20, 2016 (edited) One little off topic question: Whether this is possible to change collor for Selected but Unfocused rows ? Edited March 20, 2016 by mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
mLipok Posted March 20, 2016 Share Posted March 20, 2016 in ..\Examples\7) Original examples\lvCustDrawColors.au3 there is some issue with scrolling, scrollbar changes, but the rows on listview don not changes in all cases. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
LarsJ Posted March 21, 2016 Author Share Posted March 21, 2016 Thank you for feedback. nend, Don't miss next version. I'll probably need additional 2,000 lines of code. I think it'll fit perfectly into your snippets folder. Danyfirex, This is valuable information. It's obviously important that all this subclassing stuff is working. If not it would definitely be a showstopper. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted March 21, 2016 Author Share Posted March 21, 2016 mLipok, I'm not quite sure if I understand your question in post 4 correctly. If not, please add a new post. In a custom drawn listview it's possible to use custom back and fore colors for selected items even if the listview has not focus. The colors are drawn in the postpaint stage (after default drawing) immediately before the listview loses focus. With the functions here you can define the colors as you wish. You set the colors with the parameters $iBackUnfocus and $iForeUnfocus in ListViewColorsFonts_Set-functions (provided that the value 256 is included in $fColorsFonts flag in ListViewColorsFonts_Init). lvCustDrawColors.au3. I'm not able to verify the issue. Not even on my old XP which is very slow. When I drag the scroll bar with the mouse the rows in the listview are updated accordingly. I have tried many times this morning. I've tried with different tabs. I have not experienced any problems. Do you experience the problem consistently every time, or has it just been a single time? How is the performance of "Examples\7) Original examples\Original\lvCustDrawColors.au3" (WM_NOTIFY message handler created with GUIRegisterMsg)? How is the performance of the other examples? Eg. "Examples\2) Entire columns\8 listviews\1) Colors and fonts, GUI.au3"? Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
mLipok Posted March 21, 2016 Share Posted March 21, 2016 I make some testing My problem can be solved by changing Background color. When Background color is not standard then selected+unfocused color also changing. I ask as many computers uses old LCD monitors on which you do not see selected+unfocused listview item (unless you turn your head, or more precicly: You lay your head on the desk). Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
LarsJ Posted March 22, 2016 Author Share Posted March 22, 2016 mLipok, I understand. Sunday I forgot these lines in top of The UDF section: 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. The lines are added. Added a code example in Examples section. argumentum 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted March 30, 2016 Author Share Posted March 30, 2016 (edited) If you have tested "Examples\2) Entire columns\8 listviews\1) Colors and fonts, GUI.au3", where all listviews are created directly in the GUI, you have seen that ListView 8 performs much better than ListView 1. This is evident in particular on a not too fast PC, if you drag the scrollbar up and down with the mouse. What's the reason for the difference in performance? According to the message flow in this picture (copied from the Subclassing section) the performance should be the same in all listviews. I've studied this example more carefully by adding some ConsoleWrite statements to the callback function. It turns out that if you work intensively in the same listview for example by dragging the scrollbar, the message flow looks as shown here: The messages from ListView 1 are sent to callback function 1, 2 and 3. But the messages from ListView 3 are sent only to callback function 3. It's clear that ListView 3 performs better than ListView 1. If you work intensively in a listview the vast majority of messages follows the last diagram and only a few messages (before you start and after you have finished) follows the first diagram. The listview that performs best is the listview that's subclassed as the last one. You can verify this by adding the following lines ; Stop subclassing ListView1 ListViewColorsFonts_Exit( $idListView1 ) ; Start subclassing ListView1 ListViewColorsFonts_Init( $idListView1, 8 ) ; $fColorsFonts = 8, ( $iAddRows not used, $bNative not used ) ListViewColorsFonts_SetColumnColorsFonts( $idListView1, 0, "", 0, 0xCCCCFF ) ; Column 0: Back color = Blue ListViewColorsFonts_SetColumnColorsFonts( $idListView1, 2, "", 0, 0xFFCCCC ) ; Column 2: Back color = Red immediately after these lines (after line 240) ; Initialize listview to support column colors/fonts ListViewColorsFonts_Init( $idListView8, 8 ) ; $fColorsFonts = 8, ( $iAddRows not used, $bNative not used ) ListViewColorsFonts_SetColumnColorsFonts( $idListView8, 1, "", $iFontStyleItalic ) ; Column 1: Style = Italic ListViewColorsFonts_SetColumnColorsFonts( $idListView8, 2, "", $iFontStyleUnderline ) ; Column 2: Style = Underline in the example. Now ListView 1 is subclassed as the last one, and it'll perform best. The above applies if all listviews are created directly in main GUI. Edited March 30, 2016 by LarsJ mLipok 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
mLipok Posted March 30, 2016 Share Posted March 30, 2016 Awesome documentation as always Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
LarsJ Posted March 31, 2016 Author Share Posted March 31, 2016 Thank you, Sir. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Gianni Posted April 4, 2016 Share Posted April 4, 2016 On 19/3/2016 at 10:23 AM, LarsJ said: ... Comments are welcome. .... Hi LarsJ could you add in your ListView* udf(s) a facility that easily allows you to set the option that will highlight only the clicked item or the single subitem clicked, (or display gridlines around selected item and subitems, as well), instead of the normal behaviour that, when an item/subitem is selected (clicked), that item and all its subitems are highlighted alltoghether...(?) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
LarsJ Posted April 5, 2016 Author Share Posted April 5, 2016 Chimp, I've added the feature to the list of tasks for the next version. Gianni 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Gianni Posted April 22, 2016 Share Posted April 22, 2016 Hi I'm palyng with this UDF and I have a dobut: Can "Item colors" and "Alternating row colors" functions be combined together? Here is a listing for testing where I'm trying to use both functionalities at the same time without success. If I use Line 33 as this it works (sunday is red): ;(setting 7 alone as second parameter it works) ListViewColorsFonts_Init( $idListView, 7 ) ; 7 = Back and fore colors If I use Line 34 as this it works (Alternating rows colors): ; (setting 16 alone as second parameter it works) ListViewColorsFonts_Init( $idListView, 16 ) ; 16 = Alternating row colors (for entire listview) If I try to combine both of above In Line 35, it doesn't work. ; Combining both together it doesn't work ListViewColorsFonts_Init($idListview, BitOR(7, 16)) ; 7 and 16 combined What am I doing wrong? any help is welcome Thanks expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <date.au3> #include ".\UDFs\ListViewColorsFonts.au3" #include ".\UDFs\GuiListViewEx.au3" Example() Func Example() Local $bISO = True ; if True = 1° Day week Moonday ; if False = 1° Day week Sunday Local $aDaysOfWeek, $sDaysOfWeekISO, $iDayLen = 3 For $i = 1 To 7 $sDaysOfWeekISO &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME), $iDayLen) & "|" Next $sDaysOfWeekISO = ($bISO) ? StringMid($sDaysOfWeekISO, $iDayLen + 2) & StringLeft($sDaysOfWeekISO, $iDayLen) : StringLeft($sDaysOfWeekISO, $iDayLen * 7 + 6) ; $aDaysOfWeek = StringSplit($sDaysOfWeekISO, '|') ; _ArrayDisplay($aDaysOfWeek,$sDaysOfWeekISO) Local $hGui = GUICreate("ListView test", 1300, 500) ; Create the "skeleton" of the ListView (an empty ListView) Local $iColumns = 32 ; desired columns in the ListView (0 to 31) Local $iRows = 12 ; nr. of rows (in addition to the header) Local $sColumns = StringReplace(StringFormat('%' & $iColumns & 's', ""), " ", '|') ; as many separators as desired nr. of columns Local $idListview = GUICtrlCreateListView($sColumns, 2, 2, 1296, 496, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) For $i = 1 To 12 ; create the rows (in addition to the header) GUICtrlCreateListViewItem($sColumns, $idListview) Next ; Initialize ListView to support alternating row colors ListViewColorsFonts_Init( $idListView, 7 ) ; 7 = Back and fore colors <--- this alone works OK ;~ ListViewColorsFonts_Init( $idListView, 16 ) ; 16 = Alternating row colors (for entire listview) <--- this alone works OK ;~ ListViewColorsFonts_Init($idListview, BitOR(7, 16)) ; 7 and 16 combined <--- above combined together doesn't work ??? ListViewColorsFonts_SetAlternatingColors($idListview, _ 1, 1, _ ; $iRows = 1, $iCols = 1 0xCCFFFF, -1) ; $iBackColor = Cyan, $iForeColor = Default (black) GUISetState(@SW_SHOW) ; Fill all rows and columns with wanted data _GUICtrlListView_BeginUpdate($idListview) ; Set columns (headers) _GUICtrlListView_SetColumn($idListview, 0, @YEAR, 140, 0) ; First column header (Year) For $i = 1 To 31 ; Days of month _GUICtrlListView_SetColumn($idListview, $i, $i, 37) Next ; Set items Text Local $iYear = @YEAR, $iDayOfWeek For $iMonth = 1 To 12 _GUICtrlListView_SetItemText($idListview, $iMonth - 1, _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME)) ; Month name for $iDay = 1 To _DateDaysInMonth($iYear, $iMonth) $iDayOfWeek = ($bISO) ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay) _GUICtrlListView_SetItemText($idListview, $iMonth - 1, $aDaysOfWeek[$iDayOfWeek], $iDay) If _DateToDayOfWeekISO($iYear, $iMonth, $iDay) = 7 Then ListViewColorsFonts_SetItemColors($idListview, $iMonth - 1, $iDay, 0xCCCCFF, 0xFF0000) ; Blue, Red EndIf Next ; Next day Next; Next Month ; Set Today Green ListViewColorsFonts_SetItemColors($idListview, @MON - 1, @MDAY, 0x00FF00, 0xFF0000) ; Blue, Green ; Adjust height of GUI and ListView to fit ten rows Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows($idListview, $iRows) WinMove($hGui, "", Default, Default, Default, WinGetPos($hGui)[3] - WinGetClientSize($hGui)[1] + $iLvHeight + 20) WinMove($idListview, "", Default, Default, Default, $iLvHeight) ; Redraw listview ListViewColorsFonts_Redraw($idListview) _GUICtrlListView_EndUpdate($idListview) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example LarsJ 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
LarsJ Posted April 22, 2016 Author Share Posted April 22, 2016 That was a lot of columns. You are not doing anything wrong but flags 7 and 16 cannot be combined. Item colors (flag 7) and alternating row colors (flag 16) are drawn by two different functions. And a listview can only use one drawing function. If you had checked @error you would have seen @error = 2 with this description in the UDF: 2 - $fColorsFonts is invalid or an invalid combination of otherwise valid flags I'll take a closer look tomorrow and see if I can do something. Regards Lars. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted April 23, 2016 Author Share Posted April 23, 2016 That was easy. Check the code. Weekdays and months are in danish on my PC. Nice. expandcollapse popup#include <GUIConstantsEx.au3> #include <date.au3> #include ".\UDFs\ListViewColorsFonts.au3" #include ".\UDFs\GuiListViewEx.au3" Example() Func Example() Local $bISO = True ; if True = 1° Day week Moonday ; if False = 1° Day week Sunday Local $aDaysOfWeek, $sDaysOfWeekISO, $iDayLen = 3 For $i = 1 To 7 $sDaysOfWeekISO &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME), $iDayLen) & "|" Next $sDaysOfWeekISO = ($bISO) ? StringMid($sDaysOfWeekISO, $iDayLen + 2) & StringLeft($sDaysOfWeekISO, $iDayLen) : StringLeft($sDaysOfWeekISO, $iDayLen * 7 + 6) ; $aDaysOfWeek = StringSplit($sDaysOfWeekISO, '|') ; _ArrayDisplay($aDaysOfWeek,$sDaysOfWeekISO) Local $hGui = GUICreate("ListView test", 1300, 500) ; Create the "skeleton" of the ListView (an empty ListView) Local $iColumns = 32 ; desired columns in the ListView (0 to 31) Local $iRows = 12 ; nr. of rows (in addition to the header) Local $sColumns = StringReplace(StringFormat('%' & $iColumns & 's', ""), " ", '|') ; as many separators as desired nr. of columns Local $idListview = GUICtrlCreateListView($sColumns, 2, 2, 1296, 496, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) For $i = 1 To 12 ; create the rows (in addition to the header) GUICtrlCreateListViewItem($sColumns, $idListview) Next ; Initialize ListView to support alternating row colors ListViewColorsFonts_Init( $idListView, 7 ) ; 7 = Back and fore colors <--- this alone works OK ; Set columns (headers) _GUICtrlListView_SetColumn($idListview, 0, @YEAR, 140, 0) ; First column header (Year) For $i = 1 To 31 ; Days of month _GUICtrlListView_SetColumn($idListview, $i, $i, 37) Next ; Set items Text Local $iYear = @YEAR, $iDayOfWeek For $iMonth = 1 To 12 _GUICtrlListView_SetItemText($idListview, $iMonth - 1, _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME)) ; Month name If Not Mod( $iMonth, 2 ) Then ListViewColorsFonts_SetItemColors($idListview, $iMonth - 1, -1, 0xCCFFFF ) ; Cyan <<<<<<<<<<<< ;If Mod( $iMonth, 6 ) > 2 Then ListViewColorsFonts_SetItemColors($idListview, $iMonth, -1, 0xCCFFFF ) ; Cyan, quarters for $iDay = 1 To _DateDaysInMonth($iYear, $iMonth) $iDayOfWeek = ($bISO) ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay) _GUICtrlListView_SetItemText($idListview, $iMonth - 1, $aDaysOfWeek[$iDayOfWeek], $iDay) If _DateToDayOfWeekISO($iYear, $iMonth, $iDay) = 7 Then ListViewColorsFonts_SetItemColors($idListview, $iMonth - 1, $iDay, 0xCCCCFF, 0xFF0000) ; Blue, Red EndIf Next ; Next day Next; Next Month ; Set Today Green ListViewColorsFonts_SetItemColors($idListview, Int(@MON)-1, Int(@MDAY), 0x00FF00, 0xFF0000) ; Blue, Green ; Adjust height of GUI and ListView to fit ten rows Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows($idListview, $iRows) WinMove($hGui, "", Default, Default, Default, WinGetPos($hGui)[3] - WinGetClientSize($hGui)[1] + $iLvHeight + 4 ) WinMove(GUICtrlGetHandle($idListview), "", Default, Default, Default, $iLvHeight + 4 ) ; 4 additional pixels to account for gridlines ; Redraw listview ListViewColorsFonts_Redraw($idListview) GUISetState(@SW_SHOW) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Gianni 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Gianni Posted April 23, 2016 Share Posted April 23, 2016 Hi @LarsJ Thanks for the answer(s) and for the working code. I see, setting SubItem value to -1 will affect the entire row You are the boss of the ListViews Thank You. Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Gianni Posted May 18, 2016 Share Posted May 18, 2016 (edited) Hi LarsJ, sorry, but I'm again stuck on this little issue, I use only the ListViewColorsFonts_SetItemColorsFonts() function to set styles on items and subitems (without mixing it with other setting functions), but I got a little problem and I don't know if it's a bug, or if I am doing an improper use of this function. See line 61 on the listing, where I try to change the font and style just for "today's" cell, the new font and style (bold) is repeated also for the next cells on the same row (till next sunday's cell). also, if I comment out line 47, where I set the background pink color for the entire row of current month, then problem of the repetition of the bold style on line 61 doesn't arise instead.... I'm a bit confused about this behaviour of the udf.... What am I doing wrong? Thanks a lot for any advise. expandcollapse popup#include <GUIConstantsEx.au3> #include <date.au3> #include ".\UDFs\ListViewColorsFonts.au3" #include ".\UDFs\GuiListViewEx.au3" Example() Func Example() Local $bISO = True ; if True = 1° Day week Moonday ; if False = 1° Day week Sunday Local $aDaysOfWeek, $sDaysOfWeekISO, $iDayLen = 3 For $i = 1 To 7 $sDaysOfWeekISO &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_LONGNAME), $iDayLen) & "|" Next $sDaysOfWeekISO = ($bISO) ? StringMid($sDaysOfWeekISO, $iDayLen + 2) & StringLeft($sDaysOfWeekISO, $iDayLen) : StringLeft($sDaysOfWeekISO, $iDayLen * 7 + 6) ; $aDaysOfWeek = StringSplit($sDaysOfWeekISO, '|') ; _ArrayDisplay($aDaysOfWeek,$sDaysOfWeekISO) Local $hGui = GUICreate("ListView test", 1300, 500) ; Create the "skeleton" of the ListView (an empty ListView) Local $iColumns = 32 ; desired columns in the ListView (0 to 31) Local $iRows = 12 ; nr. of rows (in addition to the header) Local $sColumns = StringReplace(StringFormat('%' & $iColumns & 's', ""), " ", '|') ; as many separators as desired nr. of columns Local $idListview = GUICtrlCreateListView($sColumns, 2, 2, 1296, 496, Default, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES)) For $i = 1 To 12 ; create the rows (in addition to the header) GUICtrlCreateListViewItem($sColumns, $idListview) Next ; Initialize ListView ListViewColorsFonts_Init($idListview, 7) ; 7 = Back and fore colors Local $iYear = @YEAR, $iDayOfWeek ; Set columns (headers) _GUICtrlListView_SetColumn($idListview, 0, $iYear, 140, 0) ; First column header (Year) For $i = 1 To 31 ; Days of month _GUICtrlListView_SetColumn($idListview, $i, $i, 37) Next ; Set items Text For $iMonth = 1 To 12 ; scan all months (each month for each listview row) _GUICtrlListView_SetItemText($idListview, $iMonth - 1, _DateToMonth($iMonth, $DMW_LOCALE_LONGNAME)) ; Month name ; altenating rows background color If Not Mod($iMonth, 2) Then ListViewColorsFonts_SetItemColorsFonts($idListview, $iMonth - 1, -1, "", 0, 0xCCFFFF) ; set background color of current month ; current month pink on the entire row If @MON = $iMonth Then ListViewColorsFonts_SetItemColorsFonts($idListview, $iMonth - 1, -1, "", 0, 0xFFCCCC) ; set day of week on each cell of the current month For $iDay = 1 To _DateDaysInMonth($iYear, $iMonth) $iDayOfWeek = ($bISO) ? _DateToDayOfWeekISO($iYear, $iMonth, $iDay) : _DateToDayOfWeek($iYear, $iMonth, $iDay) _GUICtrlListView_SetItemText($idListview, $iMonth - 1, $aDaysOfWeek[$iDayOfWeek], $iDay) If _DateToDayOfWeekISO($iYear, $iMonth, $iDay) = 7 Then ; is it Sunday ? set colour for sunday ListViewColorsFonts_SetItemColorsFonts($idListview, $iMonth - 1, $iDay, "", 0, 0xCCCCFF, 0xFF0000) ; Blue, Red EndIf Next ; Next day Next; Next Month ; Set font, color and style only for 'Today' (Bold, green background, blue forground) ListViewColorsFonts_SetItemColorsFonts($idListview, Int(@MON) - 1, Int(@MDAY), "Arial Black", $iFontStyleBold, 0x00ff00, 0x0000FF) ; Adjust height of GUI and ListView to fit ten rows Local $iLvHeight = _GUICtrlListView_GetHeightToFitRows($idListview, $iRows) WinMove($hGui, "", Default, Default, Default, WinGetPos($hGui)[3] - WinGetClientSize($hGui)[1] + $iLvHeight + 4) WinMove(GUICtrlGetHandle($idListview), "", Default, Default, Default, $iLvHeight + 4) ; 4 additional pixels to account for gridlines ; Redraw listview ListViewColorsFonts_Redraw($idListview) GUISetState(@SW_SHOW) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Edited May 18, 2016 by Chimp LarsJ 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
LarsJ Posted May 18, 2016 Author Share Posted May 18, 2016 (edited) Chimp, You are not doing anything wrong. This is a bug. Thank you. When SubItem is -1 and the font is the default font, I had simply forgot to handle the font. Sorry. Fixed in the zip. I'll test the code over the weekend for any unforeseen side effects. ListViewColorsFonts.7z Edited May 18, 2016 by LarsJ Gianni 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now