Joined: November 20th, 2008, 6:00 pm Posts: 72 Location: Thionville, France
|
This set of functions allows to change the default color of the text and/or background of any row in any treeview.
Last updated: 15 mar 2010
Listviews and treeviews can be colored simultaneously with LTVCustomColors script, which combines listview coloring functions and treeview coloring functions described in this topic.
The idea and code are based on evl's Listview colors for individual lines (e.g. highlighting), originally from shimanov, which I ported to treeviews and added support for multiple treeviews on multiple GUIs.
Instructions:- Before coloring a treeview, you will need to call TV_Change(...) (or TV_Initialize) at least once for this treeview.
- Use TV_Change(...) to choose upon which treeview color changes are operated.
- To customize text and/or background color of a row or the entire treeview, use TV_ColorChange(...).
- As TV_Initialize(...) will not change which treeview is operated upon, you will need to call TV_Change(...) even if you used TV_Initialize(...) Other remarks:- Specify GuiControl, N:-Redraw, TreeViewName prior to make a consequent number of color changes, and GuiControl, N:+Redraw, TreeViewName afterward.
- If your script is monitoring WM_NOTIFY messages, you will need to merge your code for these messages with the one in WM_NOTIFY() function (at comment 'ADD YOUR CODE HERE'). List of functions:TV_Change(Gui_Number=1, Control=1, Select=1) OR TV_Change(Ctrl_hWnd, "", Select=1) Changes the treeview on which color changes will be applied. If the treeview has not been initialized, TV_Change() will call TV_Initialize() for the specified treeview.
Returns: 1 upon success, nothing if there was a problem (typically: the specified treeview was not found). Parameters: - Ctrl_hWnd: handle of the treeview. Second parameter must be omitted. - Gui_Number: gui containing the treeview. Defaults to 1 if omitted. - Control: instance number of the treeview in the gui OR ClassNN OR associated variable name. Defaults to the first treeview of specified gui if omitted. - Select: set to 1 (default) to also make the treeview passed in parameter the one operated upon (by means of Gui, TreeView, TreeViewName). This also will change the GUI operated upon to the one containing the treeview (by means of Gui, N:Default). TV_SetColor(Index="", TextColor="", BackColor="", Redraw=1) Changes the text and/or background color.
Returns: 1 upon success, nothing if there was a problem (typically: no treeview to operate upon). Parameters: - Index: Index of a row. Specify 0 or leave parameter blank to modify colors on the entire treeview. - TextColor: new text color of the row. Specify a negative number to reset the text color. If omitted or blank, it will not be modified. - BackColor: new background color of the row. Specify a negative number to reset the background color. If omitted or blank, it will not be modified. - Redraw: try to set this parameter to 0 in case of slowness problems. TV_GetColor(Index, WhatColor="Text") Retrieves the color of the provided row index or line number.Returns:the color as it was entered via TV_SetColor(). Parameters: - Index: Index of the row from which to retrieve color. - WhatColor: (case insensitive) specify "text" (default) to retrieve text color, specify "back" to retrieve back color. TV_Destroy(Gui_Number=1, Control=1, DeactivateWMNotify="") OR TV_Destroy(Ctrl_hWnd, "", DeactivateWMNotify= "") Destroys all variables associated with a treeview. You may want to use this function when destroying a treeview containing a large amount of colored items. You will need to reinitialize a 'destroyed' treeview to further change its colors. This function will work even if the control doesn't exist anymore (typically destroyed by means of Gui, N:Destroy). The only exception to that is if you use TV_Destroy with the control's variable name without having previously called TV_Change (or TV_Initialize) using the variable name.
Returns: 1 upon success, nothing if there was a problem (typically: the specified treeview was not found). Parameters: - Ctrl_hWnd: see TV_Change. - Gui_Number: see TV_Change. - Control: see TV_Change. - DeactivateWMNotify: for compatibility with scripts that may call WM_NOTIFY for other purposes, this parameter allows to choose whether to deactivate calls if no more treeview is to be monitored. TV_Initialize(Gui_Number=1, Control=1) OR TV_Initialize(Ctrl_hWnd, Control="") This function is internal, so you usually will not need to use it. Initializes (sets variables required for color changes) the specified treeview. Does not change the treeview currently operated upon.
Returns: 1 upon success, nothing if the treeview was already initialized or there was a problem (typically: the specified treeview was not found). Parameters: - Ctrl_hWnd: see TV_Change. - Gui_Number: see TV_Change. - Control: see TV_Change. List of extra functions:TV_GetIDFromPos(PosList, RootID="", hTV="") Retrieves the ID of a row from its position among siblings and parents' siblings.
Returns: The ID of the row if found, nothing if not found. Parameters: - PosList: a list of the positions of each parents among their siblings, separated by commas. Ex: to get the 2nd child of the 3rd parent, this parameter should be "3,2". - RootID: ID of a row to start to search from. The positions in PosList will be relative to this row. - hTV: handle of the treeview to search in. If omitted, it will use the treeview selected by last TV_Change. TV_GetPosFromID(hItem, hTV="") Retrieves the position among siblings and parents' siblings of a row from its ID.
Returns: The positions of the row if found, nothing if not found (same format as PosList, see TV_GetIDFromPos). Parameters: - hItem: the ID of the row from which to retrieve the position. - hTV: handle of the treeview to search in. If omitted, it will use the treeview selected by last TV_Change. TV_ListID(hTV="") Retrieves a list of the IDs in a treeview. Parameters: hTV: handle of the treeview to search in. If omitted, it will use the treeview selected by last TV_Change. Download:
Example: Code: #Include TVCustomColors.ahk
Gui, 4:Add, TreeView, hwndHTV1 TV_Change(4) P1_0 := TV_Add("Zeroth parent") P1_1 := TV_Add("First parent") P1_1C1 := TV_Add("Parent 1's first child", P1_1) P1_2 := TV_Add("Second parent") P1_2C1 := TV_Add("Parent 2's first child", P1_2) P1_2C2 := TV_Add("Parent 2's second child", P1_2) P1_2C2C1 := TV_Add("Child 2's first child", P1_2C2) Gui, 4:Add, TreeView, hwndHTV2 P2_1 := TV_Add("First parent") P2_2 := TV_Add("Second parent", "", "Expand") P2_1C1 := TV_Add("Parent 1's first child", P2_1) P2_2C2 := TV_Add("Parent 2's second child", P2_2, "Expand") P2_2C1 := TV_Add("Parent 2's first child", P2_2) P2_2C2C1 := TV_Add("Child 2's first child", P2_2C2)
Gui, 4:Show
TV_Change(HTV1) TV_SetColor(P1_1, 0xffff00, 0x0) TV_Change(HTV2) TV_SetColor("", 0xff00ff, 0) TV_SetColor(TV_GetIDFromPos("2,1,1"), 0x543210, 0xea87ab) return
4GuiClose: 4GuiEscape: ExitApp Return Last updated: 15 mar 2010
Released: 15 mar 2010
|
|
|