Code: Select all
Open:
GuiControl, -Redraw, % CLV.HWND
Gui, Show
GuiControl, +Redraw, % CLV.HWND
return
Code: Select all
Open:
GuiControl, -Redraw, % CLV.HWND
Gui, Show
GuiControl, +Redraw, % CLV.HWND
return
Thanks, fixes the issue, except for some flicker as just me mentioned.jNizM wrote:@Run1e add Winset, Redraw after Gui, Show
Code: Select all
Open: Gui Show WinSet, Redraw,, % "ahk_id " hwnd return
Redrawing only the listview seems to be the wanted solution, thanksjust 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:Another option would be to disable the Open menu entry while the GUI is visible.Code: Select all
Open: GuiControl, -Redraw, % CLV.HWND Gui, Show GuiControl, +Redraw, % CLV.HWND return
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
yes. tested in on few more comps at my work with same win version (win7 enterprise sp2).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?
that's ok tnx!just me wrote:Sorry, I only have Win 10 systems here, so I cannot test on Win 7.
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
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
}
}
I did not find another option as yet.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.
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
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);
}
}
}
}
Return to “Scripts and Functions (v1)”
Users browsing this forum: Bing [Bot], hiahkforum and 40 guests