@
Tekl
Actually, All you need to do is call
LV_ColorInitiate(0xebf02f)
I am not sure why I had the listview var in there, only need to specify control if using a different one. I re-copied an updated code below.
Code:
/*
HiLite - Ace
*Enable onClick Highlighting and Scroll Highlighting
*Made for the Listviews without altsubmit as there is no "Normal" events fired
Remarks:
LV_ColorInitiate( HiLite_Color) - is to be added in your startup to initialize Highlighting
*Use Color in Hex format, Example Call - LV_ColorInitiate(0xebf02f)
Buffer - Set number of lines visible above or below highlighted line while scrolling
*Default value = 1
Call MouseDown() and MouseUp() in your WheelUp/WheelDown Hotkeys or whatever you want to make the ListView Scroll with
-----Do Not need to add but can enhance preformance-----
-----I used -0x8 because of click+drag ablitiy on my listview----
#MaxHotkeysPerInterval - Set this or the Scroll hotkeys will trigger Interval Errors
-0x8 - Add this to listview , will disable Listview highlighting, this is needed if you have g_label for listview and want other events fired
*/
LV_ColorInitiate(Color=255, Gui_Number=1, Control="") { ; initiatize listview color change procedure, Default HiLite_Color = Blue (255) BGR
Global
HiLite_Color := Color
If !Control
Control = SysListView321
Gui, %Gui_Number%:+Lastfound
Gui_ID := WinExist()
ControlGet, hw_LVX_HiLite, HWND,, %Control%, Ahk_ID %Gui_ID%
OnMessage( 0x4E, "WM_NOTIFY" )
}
MouseDown(Buffer=1) {
Global
DllCall("GetScrollRange", "uint", hw_LVX_HiLite, "int", 1, "int*", min, "int*", max) ;Used in place of lv_getcount() because it also retrieves minimum range as well as maximum range
If !ScrollPos ; Set ScrollPos to 1 if empty, this is used inplace of lv_getnext()
ScrollPos = 1
If ScrollPos > %max% ; Ensure that LvX function does not draw in row that doest not exist and error out
Return
ScrollPos++ ; Increment Scrolldown position by 1
LV_Modify(ScrollPos + Buffer, "+vis") ; Add buffer to bottom of highlighted text - Increase "Buffer" to add more lines
LVX_SetColour(ScrollPos, HiLite_Color) ; Highlights current selected row, ScrollPos, Background_Color
Return
}
MouseUp(Buffer=1) {
Global
DllCall("GetScrollRange", "uint", hw_LVX_HiLite, "int", 1, "int*", min, "int*", max) ;Used in place of lv_getcount() because it also retrieves minimum range as well as maximum range
min+=1 ; Set min = to 1 or LvX function tries to draw on line 0 and errors out
If ScrollPos < %min% or !ScrollPos ; Ensure that LvX function does not draw at row 0 and error
Return
ScrollPos-- ; DeIncrement Scrolldown position by 1
LV_Modify(ScrollPos - Buffer, "+vis") ; Add buffer to Top of highlighted text - Incraese "Buffer" to add more lines
LVX_SetColour(ScrollPos, HiLite_Color) ; Highlights current selected row, ScrollPos, Background_Color
Return
}
WM_NOTIFY( p_w, p_l, p_m ) {
Global
Critical
Current_Line := NumGet(p_l + 36)+1 ; Get Current Selected Row
If ( DllCall("GetFocus") = hw_LVX_HiLite ) { ; Control has Keyboard Focus?
SendMessage, 4140, Current_Line-1, 2, , Ahk_ID %hw_LVX_HiLite% ; LVM_GETITEMSTATE
If ( ErrorLevel = 2 ) { ; LVIS_SELECTED
NumPut(0x2, p_l + 16) ; LVITEM->stateMask ; LVIS_SELECTED
SendMessage, 4139, Current_Line-1, p_l, , Ahk_ID %hw_LVX_HiLite% ; Disable Highlighting
ScrollPos := Current_Line ; Set Clicked Highlighted line = scrollposition
LVX_SetColour(Current_Line, HiLite_Color) ; Color Current_Line + Background +Text color is available but not sent in this case
Return, 0x00000010 ; CDRF_NOTIFYPOSTPAINT
}
}
If (NumGet(p_l + 0) == NumGet(lvx))
Return, LVX_Notify(p_w, p_l, p_m)
}
/* Function: LVX_Notify
Handler for WM_NOTIFY events on ListView controls. Do not use this function.
*/
LVX_Notify(p_w, p_l, p_m) {
Global lvx
If (NumGet(p_l + 0) == NumGet(lvx) and NumGet(p_l + 8, 0, "Int") == -12) {
st := NumGet(p_l + 12)
If st = 1
Return, 0x20
Else If (st == 0x10001) {
a := NumGet(p_l + 36) * 9 + 9
If NumGet(lvx, a)
NumPut(NumGet(lvx, a - 4), p_l + 48), NumPut(NumGet(lvx, a), p_l + 52)
}
}
}
/* Function: LVX_SetColour
Set the background and/or text colour of a specific row on a ListView control.
Parameters:
index - row index (1-based)
back - (optional) background row colour, must be hex code in RGB format (default: 0xffffff)
text - (optional) similar to above, except for font colour (default: 0x000000)
Remarks:
Sorting will not affect coloured rows.
*/
LVX_SetColour(Index, HiLite=255, Text="") {
Global lvx, hw_LVX_HiLite
LVX_SetEditHotkeys() ; Enable Default Hotkeys
SendMessage,4100,0,0, ,Ahk_ID %hw_LVX_HiLite% ; Get Total Number of rows for highlighting VarCapacity
VarSetCapacity(lvx, 4 + ErrorLevel * 9, 0) ; Total rows is needed when capacity is initialized so all rows can be drawn on
NumPut(hw_LVX_HiLite + 0, lvx)
A := (Index - 1) * 9 + 5
If Text
NumPut(LVX_RevBGR(Text) + 0, lvx, A)
NumPut(LVX_RevBGR(HiLite) + 0, lvx, A + 4)
WinSet, Redraw, ,Ahk_ID %hw_LVX_HiLite%
}
/* Function: LVX_RevBGR
Helper function for internal use. Converts RGB to BGR.
Parameters:
i - BGR hex code
*/
LVX_RevBGR(i) {
Return, (i & 0xff) << 16 | (i & 0xffff) >> 8 << 8 | i >> 16
}
/* Function: LVX_SetEditHotkeys
Change accept/cancel hotkeys in cell editing mode.
Parameters:
enter - comma seperated list of hotkey names/modifiers that will save
the current input text and close editing mode
esc - same as above but will ignore text entry (i.e. to cancel)
Remarks:
The default hotkeys are Enter and Esc (Escape) respectively,
and such will be used if either parameter is blank or omitted.
*/
LVX_SetEditHotkeys(enter = "Enter,NumpadEnter", esc = "Esc") {
Global lvx, lvxb
Static h1, h0
If (enter == ~1) {
If esc > 0
{
lvxb = 0
Hotkey, IfWinNotActive, Ahk_ID %esc%
}
Loop, Parse, h1, `,
Hotkey, %A_LoopField%, _lvxb
Loop, Parse, h0, `,
Hotkey, %A_LoopField%, _lvxc
Hotkey, IfWinActive
Return
}
If !enter
h1 = %enter%
If !esc
h0 = %esc%
}
_lvxc: ; these labels are for internal use:
lvxb++
_lvxb:
lvxb++
LVX_SetEditHotkeys(~1, -1)
Return
;----------------------------------------------------------------------------------
;LvX - Titan
; License:
; o Version 1.04 by Titan <http://www.autohotkey.net/~Titan/#lvx>
; o zlib License <http://www.autohotkey.net/~Titan/zlib.txt>
; http://www.autohotkey.com/forum/topic26541.html&highlight=lvx