[Class] LV_Colors - 1.1.05.00 (2024-03-16)

Post your working scripts, libraries and tools for AHK v1.1 and older
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

05 May 2017, 02:21

I did some testing and it seems that NM_CUSTOMDRAW (-12) notifications are not sent / suppressed when Gui, Show is executed while the GUI is visible and not minimized. The message handler gets only one NM_SETFOCUS (-7) notification in this case. The only workaround I found is to redraw the ListView manually, as jNizM already suggested. Because I noticed some flashing here, I recommend:

Code: Select all

Open:
GuiControl, -Redraw, % CLV.HWND
Gui, Show
GuiControl, +Redraw, % CLV.HWND
return
Another option would be to disable the Open menu entry while the GUI is visible.
User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

05 May 2017, 08:15

jNizM wrote:@Run1e add Winset, Redraw after Gui, Show

Code: Select all

Open:
Gui Show
WinSet, Redraw,, % "ahk_id " hwnd
return
Thanks, fixes the issue, except for some flicker as just me mentioned.
just me wrote:I did some testing and it seems that NM_CUSTOMDRAW (-12) notifications are not sent / suppressed when Gui, Show is executed while the GUI is visible and not minimized. The message handler gets only one NM_SETFOCUS (-7) notification in this case. The only workaround I found is to redraw the ListView manually, as jNizM already suggested. Because I noticed some flashing here, I recommend:

Code: Select all

Open:
GuiControl, -Redraw, % CLV.HWND
Gui, Show
GuiControl, +Redraw, % CLV.HWND
return
Another option would be to disable the Open menu entry while the GUI is visible.
Redrawing only the listview seems to be the wanted solution, thanks :)
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

22 Aug 2017, 05:20

great lib just me, tnx for sharing.

i have some odd bug when using this lib,
when a new window comes up on a gui which have color\s,
then showhow the content into the gui just disappeared like a "bugy smeared".
the only way to fix it is to minimize and maximize the gui.

i captured some video of this:
https://streamable.com/7shzc

will be thankful if you can make a fix for this bug (if it is?)
tnx!

edit:
added the code of the gui in the video (although its happens on every gui which included listview with colors)

Code: Select all


#NoEnv
a = notepad exist
b = notepad not exist

Gui, Add, ListView, HwndHLV Grid, index ; added Hwnd option
ColorLV := New LV_Colors(HLV, 1) ; create a new instance of LV_Colors using the 'Static' mode
Gui, Show
IfWinExist, ahk_exe notepad.exe
{
                    ; here i want the text in BLUE color
                   row := lv_add("", a) ; save the row number
                    ColorLV.Row(row, "Blue", "White") ; assign background color Blue and text color White to the added row
}
else
{
                    ; here i want the text in RED color
                    row := lv_add("", b) ; save the row number
                    ColorLV.Row(row, "Red", "White") ; assign background color Red and text color White to the added row
}
; GuiControl, +Redraw, %HLV% ; you might need to redraw the ListView to show the colors
return

GuiClose:
ExitApp

#Include Class_LV_Colors.ahk
EDIT2 :
note:
sometimes the gui not disappear Immediatey after a new window comes up on it ,
and you have the move the window over the gui some more time until you notice the bug.
Last edited by Tomer on 22 Aug 2017, 06:00, edited 4 times in total.
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

22 Aug 2017, 05:46

I'll check it.
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

22 Aug 2017, 08:51

I cannot reproduce the issue here (Win 10 Pro 1703 64-bit, AHK 1.1.25.02 64-bit). From what I see in your video it looks like the 'well-known' redrawing issue happening sometimes while resizing coloums, header clicks, sorting, fast scrolling etc. I don't know the reason in your case. Does it happen for all overlapping windows?
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

22 Aug 2017, 12:59

just me wrote:I cannot reproduce the issue here (Win 10 Pro 1703 64-bit, AHK 1.1.25.02 64-bit). From what I see in your video it looks like the 'well-known' redrawing issue happening sometimes while resizing coloums, header clicks, sorting, fast scrolling etc. I don't know the reason in your case. Does it happen for all overlapping windows?
yes. tested in on few more comps at my work with same win version (win7 enterprise sp2).
Also tested it on win server 2012 rc2 64bit. Its happend for all..

edit:
tested in on win 10 (x64, home) and its not happen at all :shock:
problem is i have more than 6000 end comp stations with win7 in my organization :cry:
any chance for win7 fix ? :roll:
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

23 Aug 2017, 03:26

Sorry, I only have Win 10 systems here, so I cannot test on Win 7.
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

23 Aug 2017, 07:12

just me wrote:Sorry, I only have Win 10 systems here, so I cannot test on Win 7.
that's ok tnx! 8-)
any tips you can provide to avoid the the well-known' redrawing issue ?
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

24 Aug 2017, 04:40

Over all the time I developed the script I never noticed this issue. Sorry, I have o idea what's might cause it in your case.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

15 Nov 2017, 10:09

I am seeing an issue with LV_Colors that is locking up ListViews

Here is some sample code.
The purpose of the code is to synchronise multiple listviews - both the scrolling and the highlighting

I can do this without LV_Colors, but all the ListViews apart from the one with focus have grey highlight lines instead of blue - I want them all to be the same color.

In this video, I am using PGDN to scroll through the listviews - see how some of the LVs glitch out and stop scrolling :(

Image

Set USE_LV_COLORS to 0 to turn of LV_Colors, and the problem goes away.
Any ideas?

Code: Select all

#SingleInstance force
#NoEnv
#include LV_Colors.ahk

USE_LV_COLORS := 1

ListViews := []
SelectedRows := []
LvFns := []
LV_Cols := []

NumLvs := 4

Loop % NumLvs {
	if (A_Index == 1){
		opts := "xm "
	} else {
		opts := "x+5 "
	}
	opts .= "w100 h200 -Multi AltSubmit hwndhwnd -Hdr"
	Gui, Add, ListView, % opts, A
	
	ListViews.Push(hwnd)
	SelectedRows.Push(0)
	LvFns.Push(0)
	lvc := new LV_Colors(hwnd)
	if (USE_LV_COLORS){
		lvc.SelectionColors(0xFF0000)
		LV_Cols.Push(lvc)
	}
	SetCallbackState(1, A_Index)
}

Gui, Show

Loop 1000 {
	Loop % NumLvs {
		Gui, ListView, % ListViews[A_Index]
		LV_Add("", "blah")
	}
}

RowHeight := GetRowHeight(ListViews[1])
return

SetCallbackState(state, lv){
	global ListViews, LvFns
	if (state){
		fn := Func("LvChanged").Bind(ListViews[lv])
		GuiControl, +g, % ListViews[lv], % fn
		LvFns[lv] := fn
	} else {
		fn := LvFns[lv]
		GuiControl, -g, % ListViews[lv], % fn		
	}
}

LVChanged(hwnd){
	global ListViews, SelectedRows, NumLvs
	if (!(A_GuiEvent == "s" || (A_GuiEvent == "I" && ErrorLevel == "SF")))
		return
	top_row := GetTopRow(hwnd)
	Loop % NumLvs {
		if (hwnd == ListViews[A_Index])
			continue
		Gui, ListView, % ListViews[A_Index]
		SetCallbackState(0, A_Index)
		if (SelectedRows[A_Index]){
			LV_Modify(A_EventInfo, "-Select")
		}
		SelectedRows[A_Index] := A_EventInfo
		LV_Modify(A_EventInfo, "Select")
		
		row := GetTopRow(ListViews[A_Index])
		ScrollRows(ListViews[A_Index], top_row - row)
		SetCallbackState(1, A_Index)
	}
}

GetTopRow(hwnd){
	SendMessage, 0x1027, 0, 0, , % "ahk_id " hwnd
	return ErrorLevel + 1
}

ScrollRows(hwnd, rows){
	global RowHeight
	critical
	SendMessage, 0x1014, 0, % RowHeight * rows, , % "ahk_id " hwnd
}

GetRowHeight(hwnd){
	VarSetCapacity(ItemBounds, 16), NumPut(boundType, ItemBounds) 
	;LVM_GETITEMRECT = LVM_FIRST + 14 = 0x100E 
	SendMessage, 0x100E, 0, &ItemBounds, , % "ahk_id " hwnd
	Top := NumGet(ItemBounds, 4, "int") 
	Bottom := NumGet(ItemBounds, 12, "int") 
	return Bottom - Top 
}

GuiClose:
	ExitApp
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

15 Nov 2017, 16:53

Add Critical to your LVChanged function maybe?
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

15 Nov 2017, 17:18

BTW if anyone can replicate this code in C++ (Or even better, C#) then please do let me know. I have looked around and found some snippets, but not got anything to work.
I managed to get some access to an AHK LV in C# (I could get the top row number of the LV) but I could not get some of the other SendMessage calls to work.
I think a little DLL which can colour and synchronize LVs would be nice for my LogSync project :)
Bkid
Posts: 31
Joined: 13 Jun 2014, 12:19

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

15 Nov 2017, 17:35

I'm having this issue as well, and it seems like the issue is occurring on this piece of code:

Code: Select all

On_WM_NOTIFY(W, L, M, H) {
      ; Notifications: NM_CUSTOMDRAW = -12, LVN_COLUMNCLICK = -108, HDN_BEGINTRACKA = -306, HDN_BEGINTRACKW = -326
      Critical, % This.Critical
      If ((HCTL := NumGet(L + 0, 0, "UPtr")) = This.HWND) || (HCTL = This.Header) {
         Code := NumGet(L + (A_PtrSize * 2), 0, "Int")
         If (Code = -12)
            Return This.NM_CUSTOMDRAW(This.HWND, L)
         If !This.SortColumns && (Code = -108)
            Return 0
         If !This.ResizeColumns && ((Code = -306) || (Code = -326))
            Return True
      }
   }
Changing the status of Critical in there doesn't seem to help, either. One thing I have noticed is that using scroll bars to scroll does not cause this issue, as I believe it only happens when you use the mousewhell to scroll, but I'm unsure as to exactly why.
list-nli

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

16 Nov 2017, 03:40

@evilC perhaps related/similar https://autohotkey.com/boards/viewtopic ... 223#p42223 (see post where just me links to, perhaps it is "just the way it is")
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

16 Nov 2017, 04:42

Hi evilC,

I cannot reproduce your drawing issues / freezing here (Win 10 x64, AHK 1.1.25.02 x64, Intel Core I3-2310M @ 2.10 GHz, Intel HD Graphics 3000), but I see some stuttering. Both are knownn issues.

ListViews are rather talkative controls. You tie every WM_NOTIFY message and every g-label call to the same functions. This might be 'a bit to much stress' for AHK.
Class_LV_Colors wrote:

Code: Select all

; To avoid the loss of Gui events and messages the message handler might need to be set 'critical'. This can be
; achieved by setting the instance property 'Critical' to the required value (e.g. MyInstance.Critical := 100).
; New instances default to 'Critical, Off'. Though sometimes needed, ListViews or the whole Gui may become
; unresponsive under certain circumstances if Critical is set and the ListView has a g-label.
I did not find another option as yet.
treashunter

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

16 Nov 2017, 08:10

I have the same issues - however i think in my case it is exaggerated because i am using the LV's inside of ScrollGUI's(Again, thanks Just Me!). So - when i scroll the child gui, all the LV's are attempting to draw, and the problem is very evident. I remove Lv_Colors, and all is well.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

16 Nov 2017, 08:14

I managed to find a C# library which wraps the WinAPI and appears to be providing the functionality that we need.
http://mwinapi.sourceforge.net/doc/index.html

Code: Select all

IntPtr hwnd = (IntPtr)0x350dfa; // hwnd of an AHK LV
var sysWindow = new SystemWindow(hwnd);

var lv = SystemListView.FromSystemWindow(sysWindow);
var c = lv.Count; // Number of rows in the LV
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: [Class] LV_Colors - 1.1.04.01 (2016-05-03)

16 Nov 2017, 12:37

Significant progress!

I have had to add some missing methods to the mwinapi repository, I have forked it here: https://github.com/evilC/mwinapi/

In there is a Test App which can color the rows of an AHK ListView

I am following the code from here, I am trying to replicate what the EraseAlternatingRowBkgnds function is doing (Without alternating, I just wanted to see if I could paint rows, which I can)

Code: Select all

using ManagedWinapi.Windows;
using System;

/// <summary>
/// Tries to alter the colours of rows in a ListView from another application
/// Be sure to run TestWindow.exe (Or TestWindow.ahk if you have AutoHotkey installed) before running!
/// </summary>
namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            SystemWindow testWindow = null;
            SystemWindow lvWindow = null;

            foreach (var window in SystemWindow.AllToplevelWindows)
            {
                if (window.Title == "Test AHK LV")
                {
                    testWindow = window;
                    break;
                }
            }

            if (testWindow == null)
            {
                Console.WriteLine("Test window not found");
                return;
            }

            foreach (var window in testWindow.AllChildWindows)
            {
                if (window.PreviewContent.ComponentType == "DetailsListView")
                {
                    lvWindow = window;
                    break;
                }
            }

            if (lvWindow == null)
            {
                Console.WriteLine("ListView not found in Test window");
                return;
            }

            var lv = SystemListView.FromSystemWindow(lvWindow);

            var rect = lv.ClientRect;
            var iItems = lv.CountPerPage;
            var iTop = lv.TopIndex;

            var pt = lv[iTop].Position;
            for (int i = iTop; i <= iTop + iItems; i++)
            {
                rect.Top = pt.Y;
                rect.Bottom = lv[i + 1].Position.Y;
                var result = lvWindow.FillRect(rect, 0x0000FF);
            }
        }
    }
}
Image

There is still a fair amount of work to go yet, I don't really understand all the processes involved.
If anyone who is familiar with what needs to be done wants to collaborate, let me know...

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gongnl and 64 guests