Gui, +LastFound Gui, Add, ListView, x5 y5 w200 h200 vLV_Sample, index|day LV_Add( "", 1, "Monday" ) LV_Add( "", 2, "Tuesday" ) LV_Add( "", 3, "Wednesday" ) LV_Add( "", 4, "Thursday" ) LV_Add( "", 5, "Friday" ) LV_Add( "", 6, "Saturday" ) LV_Add( "", 7, "Sunday" ) LV_ModifyCol( 1, "AutoHdr" ) LV_ModifyCol( 2, "AutoHdr" ) ;nothing special up to this point LV_ColorInitiate() ; (Gui_Number, Control) - defaults to: (1, SysListView321) Gui, Show, x50 y50 w210 h210 LV_ColorChange(1, "FFFFFF", "0000FF") msgbox, 1st line is highlighted LV_Modify(1, "Select") msgbox, Now the 1st line is selected - after un-selecting it won't have the custom colour until using WinSet, Redraw LV_Modify(1, "-Select") msgbox, Now using WinSet, Redraw WinSet, Redraw,, ahk_id %hw_LV_ColorChange% ; can put this line elsewhere in script after all changes have been made Return GuiClose: GuiEscape: Exitapp ;============================================================================================================================ ; LISTVIEW HIGHLIGHTING FUNCTIONS ;============================================================================================================================ /* struct NMHDR { HWND hwndFrom; uint4 0 UINT idFrom; uint4 4 UINT code; uint4 8 } 12 */ /* struct NMCUSTOMDRAW { NMHDR hdr; 12 0 DWORD dwDrawStage; uint4 12 HDC hdc; uint4 16 RECT rc; 16 20 DWORD_PTR dwItemSpec; uint4 36 UINT uItemState; uint4 40 LPARAM lItemlParam; int4 44 } 48 */ /* struct NMLVCUSTOMDRAW { NMCUSTOMDRAW nmcd; 48 0 COLORREF clrText; uint4 48 COLORREF clrTextBk; uint4 52 #if (_WIN32_IE >= 0x0400) int iSubItem; int4 56 #endif #if (_WIN32_IE >= 0x560) DWORD dwItemType; uint4 60 COLORREF clrFace; uint4 64 int iIconEffect; int4 68 int iIconPhase; int4 72 int iPartId; int4 76 int iStateId: int4 80 RECT rcText; 16 84 UINT uAlign; uint4 100 #endif } 104 */ LV_ColorInitiate(Gui_Number=1, Control="") ; initiate listview color change procedure { global hw_LV_ColorChange If Control = Control =SysListView321 Gui, %Gui_Number%:+Lastfound LV_Color_Gui_ID := WinExist() If A_DetectHiddenWindows =Off ; initialise before gui shown { DetectHiddenWindows, On ControlGet, hw_LV_ColorChange, HWND,, %Control%, ahk_id %LV_Color_Gui_ID% DetectHiddenWindows, Off } Else ControlGet, hw_LV_ColorChange, HWND,, %Control%, ahk_id %LV_Color_Gui_ID% OnMessage( 0x4E, "WM_NOTIFY" ) } LV_ColorChange(Index="", TextColor="", BackColor="") ; change specific line's color or reset all lines { local TextColor_B, TextColor_RG, BackColor_B, BackColor_RG If Index = Loop, % LV_GetCount() LV_ColorChange(A_Index) Else { If TextColor != ; change color format from RGB to BRG { StringRight, TextColor_B, TextColor, 2 StringTrimRight, TextColor_RG, TextColor, 2 TextColor =0x%TextColor_B%%TextColor_RG% StringRight, BackColor_B, BackColor, 2 StringTrimRight, BackColor_RG, BackColor, 2 BackColor =0x%BackColor_B%%BackColor_RG% } Line_Color_%Index%_Text := TextColor Line_Color_%Index%_Back := BackColor WinSet, Redraw,, ahk_id %hw_LV_ColorChange% ; can put this line elsewhere in script after all changes have been made } } WM_NOTIFY( p_w, p_l, p_m ) { local draw_stage, Current_Line, Index if ( DecodeInteger( "uint4", p_l, 0 ) = hw_LV_ColorChange ) { if ( DecodeInteger( "int4", p_l, 8 ) = -12 ) { ; NM_CUSTOMDRAW draw_stage := DecodeInteger( "uint4", p_l, 12 ) if ( draw_stage = 1 ) ; CDDS_PREPAINT return, 0x20 ; CDRF_NOTIFYITEMDRAW else if ( draw_stage = 0x10000|1 ){ ; CDDS_ITEM Current_Line := DecodeInteger( "uint4", p_l, 36 )+1 LV_GetText(Index, Current_Line) ; change this line if the line number is not in the 1st column! If (Line_Color_%Index%_Text != "") { EncodeInteger( Line_Color_%Index%_Text, 4, p_l, 48 ) ; foreground EncodeInteger( Line_Color_%Index%_Back, 4, p_l, 52 ) ; background } } } } } DecodeInteger( p_type, p_address, p_offset, p_hex=true ) { old_FormatInteger := A_FormatInteger ifEqual, p_hex, 1, SetFormat, Integer, hex else, SetFormat, Integer, dec StringRight, size, p_type, 1 loop, %size% value += *( ( p_address+p_offset )+( A_Index-1 ) ) << ( 8*( A_Index-1 ) ) if ( size <= 4 and InStr( p_type, "u" ) != 1 and *( p_address+p_offset+( size-1 ) ) & 0x80 ) value := -( ( ~value+1 ) & ( ( 2**( 8*size ) )-1 ) ) SetFormat, Integer, %old_FormatInteger% return, value } EncodeInteger( p_value, p_size, p_address, p_offset ) { loop, %p_size% DllCall( "RtlFillMemory", "uint", p_address+p_offset+A_Index-1, "uint", 1, "uchar", p_value >> ( 8*( A_Index-1 ) ) ) } ;============================================================================================================================