[SOLVED] Treeview flicker w. Hottrack when running inside NPP Plugin (dark mode) lazarus / 31-LCL ---------------------------------------------------------------------- d7_2_laz · 2024-12-17 14:04 Made good progress to bring an old 32bit DLL plugin for Notepad++ to Lazarus 64bit. The code base for the demo i experiment with is from "Notepad++ Plugin Template for Delphi & Lazarus" https://bitbucket.org/rdipardo/delphiplugintemplate/src/default/ After some beginner struggle it seems to work quite fine. Regarding the gui there are only two major things left. The one i'd like to ask here, because i think it might be LCL related too. Treeview (will need a bit additional work on custom paint here, no problem): In my own component (based on custom treeview) now i had to notice heavy horrible flicker on mouse move. Tried to find the reason: it is here:     TreeviewXY.Hottrack := true. Without Hottrack no flicker.  And, no flicker in 'normal' mode (light theme) too. What's going on? What i do assume is that there is a concurrent painting LCL vs. NPP themeing where both are disturbing and triggering each other, which results in a heavy flicker. Pls. note that i use myself extensively custom drawing without seeing such flicker. I could reproduce simply by placing a shelltreeview onto a plugin demo docking form. Hotrack on:    heavy flicker in dark mode Hotrack off:   no flicker at all Unfortunately i need the Hottrack for some reasons and won't like to switch it off. Found the guilty line here: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //treeview.inc:procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);begin.............................    Invalidate;     // OOPS! This will repaint the whole control .....end; From my own code for 'mouse hover' i was used for such case: - repaint the line where the mouse is over - repaint/refresh the line the mouse pointer had left That had been ugly enough, because i had been forced to duplicate the whole treeview paint code, only because there is not measure to override/influence the color of the background erasure at the beginning (i had posted a special forum's topic on this times ago). Anyhow. My question to the LCL experts: is there a more granular approach possible, without engaging the massive cavalry of invalidating all? If someone is interested to try a test project: i can provide one, which would only require: Lazarus 3.x (up) Windows 64 bit A notepad++ 64bit installation recent version (i mainly prefer portable versions) Select "dark mode" in the NPP options And adapt two paths in the project settings. Edit: i assume that the Delphi users of the demo plugin template don't have this problem, as here the treeview is OS-based, not pure VCL object, differently to Lazarus. ---------------------------------------------------------------------- d7_2_laz · 2024-12-17 14:45 I just did a little POC, and yeees It works, but of course it covers only half of the story. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);var aNode: TTreeNode; R: TRect;begin.........   // Invalidate;   // please no brute force here   aNode := GetNodeAtY(Y);   If aNode <> nil then begin       R := ANode.DisplayRect(False);       InvalidateRect(Handle, @R, True);   end; The previous mouse-hovered, now mouse-left node would be needed to be remembered and InvalidateRect'ed too. This memory would be needed to be resetted when another context appears. Any ideas? ---------------------------------------------------------------------- d7_2_laz · 2024-12-17 15:23 POC, part 2 - yeees - would work perfectly i think: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //comctrls.pp:  TCustomTreeView = class(TCustomControl)     FHotTrackedPrevNode: TTreeNode; //treeview.inc:    constructor TCustomTreeView.Create(AnOwner: TComponent);        FHotTrackedPrevNode := nil;     procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);       // Invalidate;    // please no brute force       if Assigned(FHotTrackedPrevNode) then begin        if FHotTrackedPrevNode.Visible then begin           R := FHotTrackedPrevNode.DisplayRect(False);           InvalidateRect(Handle, @R, True);        end;        FHotTrackedPrevNode := nil;      end;      if Assigned(FNodeUnderCursor) then begin          R := FNodeUnderCursor.DisplayRect(False);          InvalidateRect(Handle, @R, True);          FHotTrackedPrevNode := FNodeUnderCursor;      end; Would this make sense? ---------------------------------------------------------------------- d7_2_laz · 2024-12-17 15:30 For the NPP plugin the horrible flicker fully went away .. Just retested outside the NPP plugin stuff, with a regular stand-alone exe, and felt that even this would behave a bit more smoother now ... Any opinions about? ---------------------------------------------------------------------- AlexTP · 2024-12-17 15:38 It is right approach. If I knew about this flicker before, I would do the same. PS. Welcome to write plugin for _my_ editor, see signature. ---------------------------------------------------------------------- AlexTP · 2024-12-17 15:40 And pls check - is UpdateHotTrack called when I move mouse inside single tree node? If so you call InvalidateRect twice for the same item. ---------------------------------------------------------------------- d7_2_laz · 2024-12-17 16:10 Quote from: AlexTP on December 17, 2024, 04:40:40 pmAnd pls check - is UpdateHotTrack called when I move mouse inside single tree node? If so you call InvalidateRect twice for the same item. Good point Alex! Means, something like this ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);var aNode: TTreeNode; R: TRect; bDoInvalidate: Boolean;begin...........  // Invalidate;    // Please no brute force here   if Assigned(FHotTrackedPrevNode) then begin    if FHotTrackedPrevNode.Visible then begin       bDoInvalidate :=          ((Not Assigned(FNodeUnderCursor)) Or (FHotTrackedPrevNode.Index <> FNodeUnderCursor.Index));       if bDoInvalidate then begin          R := FHotTrackedPrevNode.DisplayRect(False);          InvalidateRect(Handle, @R, True);       end;    end;    FHotTrackedPrevNode := nil;  end;  if Assigned(FNodeUnderCursor) then begin      R := FNodeUnderCursor.DisplayRect(False);      InvalidateRect(Handle, @R, True);      FHotTrackedPrevNode := FNodeUnderCursor;  end;end; ---------------------------------------------------------------------- AlexTP · 2024-12-17 16:45 Something like this, thanks. ---------------------------------------------------------------------- AlexTP · 2024-12-17 17:00 If a node is deleted programmatically, you should handle this and maybe Nil the FHotTrackedPrevNode. ---------------------------------------------------------------------- d7_2_laz · 2024-12-17 19:08 But if a node is deleted programmatically, eg. triggered by an external system - db, file system or such -, and this should be (randomly) the FHotTrackedPrevNode, then it will be already nil'ed, won't it? Btw., in an app i did for own usage with same scenario, i didn't use the ttreenode as info about "previous", but the node's index. Don't know if this is a better way ('better a dangling integer than a dangling node'?). If this should appear as more appropriate, then I'd like to change that of course. Anyhow i'd need to retrieve back then the ttreenode itself from the index at each mouse move, at least for to ask if it' s visible; hm. ---------------------------------------------------------------------- AlexTP · 2024-12-18 06:58 Yes, better to have dangling index than dangling TTreeNode, so save to Prev index instead, and calculate Node from it. ---------------------------------------------------------------------- d7_2_laz · 2024-12-18 08:46 Yes Alex, i'd agree and change this. Before i do, i'd like to share an observation: Need to go one step back. I have im my custom painting two differenct scenarios, and both should be preserved by the change for not to be too restrictive. Note, the InvalidateRects done are the trigger, so to say, that on the customdraw side the correct input is given (= node xy needs to be repainted). Otherwise the customdraw might code what it wants, but the code won't be called ... No invalidation, no painting possible. Ok, mouse-wheel. Scrolling within the tree via mouse wheel up and down. How a "hottracked line" should behave, when one uses the mousewheel ? 2 possible flavours (as option):   when wheeling up, a) the hottracked line stays statically, where it is (and the contents moves underneath it away, going upwards)) b) the hottracked line moves up resp. down too (MS-like style). Selected line and hovered line do change it's position. I checked if the change proposal would support both behaviour options. - The initial proposal (from reply #2) does it; ok. Had no side- effects. - The last proposal does not reliably. Sometimes it may happen one highlighted line to remain as painting relict. Here, the prev-info had been nil'ed out too early. With other words: the check, if FHotTrackedPrevNode and FNodeUnderCursor are different, might be too thrifty when using the mousewheel. Aa due to the movement of the wheel both will cross heavily each other (in flavour a.) and so some needed line-invalidations might go lost. So imo the easier/first solution (logic) here would be the better, as both flavours mentioned could be done with it fine. ---------------------------------------------------------------------- AlexTP · 2024-12-18 13:26 I always thought that even for mousewheel, HotTrack must affect the node under cursor. If it makes some difficulty, it's bad. ---------------------------------------------------------------------- d7_2_laz · 2024-12-18 15:35 Hi Alex, not bad, doable. - Hover node, scroll mousewheel -> the original node under the cursor wanders away, cursor stays at same position as before (flavour 1) - Hover node, scroll mousewheel -> node under the cursor wanders away, but the hover marker follows him (flavour 2) In my standalone-exe i implemented both (as option) with custom drawing. The essential part here is only that the invalidation rules do send the right invalidations for any, so that a programmer can decide. The proposal now is here as follows - with using an index instead of a ttreenode for to remember the prev state - i tried to cover your correct note, avoid "InvalidateRect twice for the same item", by comparing the 'Top's of both InvalidateRects and do only the first one if the Tops are identical.   But i'm not fully convinced. Sometimes i felt sporadical relicts though, not quite sure. So i show it as comments here only. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //comctrls.pp:  TCustomTreeView = class(TCustomControl)   private     FHotTrackedIdxPrevNode: Integer; //treeview.inc:  constructor TCustomTreeView.Create(AnOwner: TComponent);     FHotTrackedIdxPrevNode := -1;   procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);  var aNode: TTreeNode; R: TRect; // rTop: Integer;  begin     .........     //Invalidate;    // Please no brute force here      //rTop := -1;     if FHotTrackedIdxPrevNode > -1 then begin        aNode := Items[FHotTrackedIdxPrevNode];        if (Assigned(aNode) And aNode.Visible) then begin           R := aNode.DisplayRect(False);         InvalidateRect(Handle, @R, True);           //rTop := R.Top;      end;        FHotTrackedIdxPrevNode := -1;     end;     if Assigned(FNodeUnderCursor) then begin        R := FNodeUnderCursor.DisplayRect(False);        //if R.Top <> rTop then      InvalidateRect(Handle, @R, True);        FHotTrackedIdxPrevNode := FNodeUnderCursor.AbsoluteIndex;     end; My concern here is mainly, to minimize flicker AND to assure that the TCustomTreeView.UpdateHotTrack would do the _correct_ invalidations for any case of custom painting. ---------------------------------------------------------------------- AlexTP · 2024-12-18 15:43 This code looks OK, so only the testing (with mousewheel too) will show is it correct or not... PS. Indent = 3 spaces? weird. 2 spaces better. ---------------------------------------------------------------------- d7_2_laz · 2024-12-18 18:31 Quote from: AlexTP on December 18, 2024, 04:43:28 pmThis code looks OK, so only the testing (with mousewheel too) will show is it correct or not... PS. Indent = 3 spaces? weird. 2 spaces better. Did that intensively with my standalone-app, where i had implemented the customdraws for that. Any other tester would of course be very welcome. -> One or the other should use "HotTrack" in his code, right? Back to the NPP plugin: flicker is (nearly (*)) fully solved here, as mentioned. rdipardo had added a treeview demo in his template yesterday (and i could spend a demo test project with that, as noted at the beginning here). But there's no special custom draw dealing with hover herein. It covers only painting of the background, expand sign, and item text correctly, and with the update also the scrollbars themed. So it's no good test area for this special thing 'hovering' here. In my plugin i'm about to convert however there is this hovering mechanism, and it behaves fine, just as in the stand-alone app. (*) Let's say flicker shrinks from 90% to 2%, as there is a very very little painting movement - only in the plugin! - one still can see when hovering an item. A bit more than in the stand-alone app. But nothing compared to the original situation. Indentation: changed to 2 spaces. I'd like to propose it in the bug-tracker. Where imo it's not a bug at all of course. We're speaking about a bit of more support when entering a still more or less unexplored territory. A little fine- tuning. What do you think? Maybe i'll do some more tests about "avoid InvalidateRect twice for the same item" though before; i'll see. But in any case, I will keep a close eye on it in daily use to see if it proves effective before, for a week. A word about the origin of the topic: imo a dark theme is a proof that mercilessly exposes any weakness of a code, any unhandled white areas / erasures within a dark theme are directly visible. And the more if it's in a plugin. There's a theme code, here by NPP via OS calls, the 'host application's' own drawsings, and the user's own custom drawing on top as a third layer. - Very demanding. ---------------------------------------------------------------------- d7_2_laz · 2024-12-19 09:22 In my equality query in reply #6 - for not to call InvalidateRect twice for the same item - i did a mistake on the fly, having used "Index" instead of "AbsoluteIndex". My bad ... sorry! So now it behaves without abnormalies with both mousewheel flavours: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);var aNode: TTreeNode; R: TRect; previdx: Integer;   // rTop: Integerbegin.....  //Invalidate;  previdx := FHotTrackedIdxPrevNode;  if FHotTrackedIdxPrevNode > -1 then begin    aNode := Items[FHotTrackedIdxPrevNode];    if (Assigned(aNode) And aNode.Visible) then begin      R := aNode.DisplayRect(False);      InvalidateRect(Handle, @R, True);    end;    FHotTrackedIdxPrevNode := -1;  end;  if Assigned(FNodeUnderCursor) then begin    R := FNodeUnderCursor.DisplayRect(False);    if not (previdx = FNodeUnderCursor.AbsoluteIndex) then // Not call InvalidateRect twice for the same item      InvalidateRect(Handle, @R, True);    FHotTrackedIdxPrevNode := FNodeUnderCursor.AbsoluteIndex;  end; Now back to the original topic: as illustration i add two short videos for to show - the behaviour before (just added a shelltreeview to rdiparos's demo. Both actually have only a rudimentary painting. Eg. no icons, no hovering. It should only demonstrate the original flicker topic) - and after the change the work-in-progress component flicker-free within the plugin. ---------------------------------------------------------------------- d7_2_laz · 2024-12-19 09:23 The second one separately due to size restricion ---------------------------------------------------------------------- AlexTP · 2024-12-19 11:05 Thanks. Looks good. Offtopic: I see issue on Windows 10 with CudaText with dark theme: first painting of UI makes flicker - it shows some white areas, then CudaText dark theme is applied. Flicker of white areas. Did you see it in your project with NPP? ---------------------------------------------------------------------- d7_2_laz · 2024-12-19 14:47 Hello Alex, no, not especially with this NPP plugin. But yes, meanwhile it's in general a very well-known terrain to me. Don't know your details here, but there might be a bunch of measures, some also proposed to metadarkstyle (had previously some issues here, see e.g. for flicker in StatusBar): Basically it' s so that the OS or widgetset might paint the background in light, then comes the dark theme painting, and the component that might paint too. Every light painting that stays a while will be directly noticed as flicker, promised! Especially if a process needs time until it starts. - Intercept the WM_ERASEBKGND eg. in message loop  resp. WMEraseBackground message, assure to paint dark bg here (instead of let others do white painting) and return True in message loop - Maybe defer long operations triggered in WM_CREATE to a phase directly afterwards, so that other controls have a chance to build first. Or your control, with somehow deferred generation of it's contents - Assure that containers(!) of the control, TPanel&Co, will be erased in dark too (easy example on app level below), not focus only the control itself - Check Invalidates that are too global  ;-) - I assume that well-known things like property DoubleBuffered, LockWindowUpdate, BeginUpdate/EndUpdate are already checked - For some base components like TreeView ListView, others might have equivalents, it might be worthy to try out ovrrride possibilities at early creation stage, eg. in CreateWnd, maybe other window styles, SendMessages etc.   Caution, some measure might speedup in light mode, but might not be good for dark mode, and vice versa   So one might have something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure .CreateWnd;var Style: Dword;begin  inherited CreateWnd;  ControlStyle := ControlStyle + [csOpaque];   //  Add,,.  if HandleAllocated then begin     If Not IsDarkModeEnabled then begin        Style := ListView_GetExtendedListViewStyle(Handle);        Style := Style or LVS_EX_DOUBLEBUFFER;        ListView_SetExtendedListViewStyle(Handle, Style);     end else begin...    end;... --- Easy examples for overriding WMEraseBgnd on app level for standard (not subclassed) controls: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // For dark mode flickering  TSplitter = class(ExtCtrls.TSplitter)    procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;  end;  TPanel = class(ExtCtrls.TPanel)    procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;  end;  TEdit = class(StdCtrls.TEdit)     // Fix dark mode white flicker in a very long entry field   procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;  end; // For dark mode flickeringprocedure TSplitter.WMEraseBkgnd(var Message: TLMEraseBkgnd);var vRect: TRect;begin  if Not IsDarkModeEnabled then     exit;  if Message.DC = 0 then Exit;  Brush.Color := $00353535;  vRect := Rect(0, 0, Width, Height);  FillRect(Message.DC, vRect, Brush.Reference.Handle);end; // Drawback here: generates flicker at Resize. So, achieve via a flag (in Tag) that this will only be executed in the starting phaseprocedure TPanel.WMEraseBkgnd(var Message: TLMEraseBkgnd);var vRect : TRect;begin  if Not IsDarkModeEnabled then     exit;  if Not (Self.Tag = -1) then  // Values to be set somewhere else, at me eg. initialized in FormCreate and reset in TFormXYZ.AppIdle     exit;  if Message.DC = 0 then Exit;  Brush.Color := $00353535;  vRect := Rect(0, 0, Width, Height);  FillRect(Message.DC, vRect, Brush.Reference.Handle);end; // Drawback here: generates flicker at Resize. So, achieve via a flag (in Tag) that this will only be executed in the starting phaseprocedure TEdit.WMEraseBkgnd(var Message: TLMEraseBkgnd);var vRect : TRect;begin  if Not IsDarkModeEnabled then     exit;  if Not (Self.Tag = -1) then  // Values to be set somewhere else, at me eg. initialized in FormCreate and reset in TFormXYZ.AppIdle     exit;  if Message.DC = 0 then Exit;  Brush.Color := $00353535;  vRect := Rect(0, 0, Width, Height);  FillRect(Message.DC, vRect, Brush.Reference.Handle);end; Does one of those things somehow influences? ---------------------------------------------------------------------- d7_2_laz · 2024-12-19 14:59 Oh, just looked ... in my pagecontrrol unit, where a pagecontrol and your attabs are in, i have: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TPageControl = class(ComCtrls.TPageControl)      procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;  end;   TATTabs = class(attabs.TATTabs)      procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;  end; procedure TPageControl.WMEraseBkgnd(var Message: TLMEraseBkgnd);var vRect : TRect;begin  if Not IsDarkModeEnabled then     exit;  if Message.DC = 0 then Exit;  if FFirsttime then     FFirsttime := False  else     exit;  Brush.Color := $00353535;  vRect.Left := 0;  vRect.Top := 0;  vRect.Width := Width;  vRect.Height := Height;  FillRect(Message.DC, vRect, Brush.Reference.Handle);end; procedure TATTabs.WMEraseBkgnd(var Message: TLMEraseBkgnd);var vRect : TRect;begin  if Not IsDarkModeEnabled then     exit;  if Message.DC = 0 then Exit;  Brush.Color := $00353535;  vRect.Left := 0;  vRect.Top := 0;  vRect.Width := Width;  vRect.Height := Height;  FillRect(Message.DC, vRect, Brush.Reference.Handle);end; ---------------------------------------------------------------------- AlexTP · 2024-12-19 17:26 Erasebkgnd: I am almost suceeded! Added LM_ERASE..... handler to ATSynEdit and I see initial repaint does flicker with green (testing color in handler). Thanks! I also modified WM_ERASE.... handler in ATTabs so now you don't need your workaround. ---------------------------------------------------------------------- d7_2_laz · 2024-12-19 18:51 Thanks for feedback Alex, please tell if it has good effects at the end. Good test with color green (case there are some nested containers interfering .. which one might be responsible?) For the "WMEraseBkgnd" examples, i just added a (needed) code comment above, where i had set the "Self.Tag" flag here. I have:  set in FormCreate, changed in AppIdle. This could be interesting when dealing with problems exclusively in the start phase. In FormActivate is was not always helpful. - Example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormXYZ.FormCreate(Sender: TObject);begin    if IsDarkModeEnabled then begin       efDirOut.Tag := -1;  // Flag to process WMEraseBkgnd       PanelUpper.Tag := -1;       Application.OnIdle := AppIdle;    end;  And sometimes the procedure was good for the start phase, but counterproductive for Resize, window Maximize, return from the task bar etc. A question of testing ... And thanks for the info about the change in ATTabs! ---------------------------------------------------------------------- 440bx · 2024-12-20 05:22 I just wanted to mention that sometimes it is simpler (and cheaper code-wise) to simply set the background brush (which is used to erase the background) to a NULL_BRUSH. Basically this setting allows erasing the background  without erasing the background since the NULL_BRUSH has no effect on the background. disclaimer: I don't know how well this will work in the LCL but works very nicely when using just the WinApi. HTH. ---------------------------------------------------------------------- d7_2_laz · 2024-12-20 09:18 Interesting 440bx! But wouldn't that mean that potentially any other unwanted color would remain for a while in the target area? Maybe you could point to some example snippet. Btw i realized that i had been somehow unprecise that i had not returned a message result in callbacks using LM_ERASEBKGND instead of WM_ERASEBKGND (here it is needed). In theory this return value (1 resp. true) is a Must (meaning: job done, don't do it again) for the purpose. Afair in callbacks of 'Message: TLMEraseBkgnd' it hadn't make a difference in practice and so i had negelected it. Not sure yet, would need to re-dig into. Maybe anybody knows. Maybe i was wrong and that had been the reason why i had, in a few cases, some Resize flicher issues to handle separately. Anyhow: to my experience those measures sum up to a better appearance. ---------------------------------------------------------------------- 440bx · 2024-12-20 09:51 Quote from: d7_2_laz on December 20, 2024, 10:18:00 amInteresting 440bx! But wouldn't that mean that potentially any other unwanted color would remain for a while in the target area? Maybe you could point to some example snippet. You'll find fully working example code at https://forum.lazarus.freepascal.org/index.php/topic,53791.msg398393.h tml#msg398393 The examples BitBlt, StretchBlt and SelectClipRgn (in the following post) all use a NULL_BRUSH. Using a NULL_BRUSH should be equivalent to not clearing the background.  IOW, whatever was in the background  remains there after being "erased" with a NULL_BRUSH. ---------------------------------------------------------------------- d7_2_laz · 2024-12-20 10:06 Thank you! I'll see if i can a test next within the given context. ---------------------------------------------------------------------- 440bx · 2024-12-20 10:13 You're welcome. ---------------------------------------------------------------------- d7_2_laz · 2024-12-20 20:39 ... but couldn't bring such easily to work. The examples are constructed as 'traditional' Win-programs based on WinMain, CreateWindowEx, WndProc etc. But is it possible, and how would it be possible within a FormCreate to modify the background brush handle of the form, better: a control ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure THelloWorldDockingForm.FormCreate(Sender: TObject);var .......  wnd: Windows.TWNDClassEx; szClassName: String;begin....  szClassName := Application.ClassName;  // 'TApplication'  if GetClassInfoEx(hInstance, PChar(szClassName), @wnd) then  //szClassName := 'THelloWorldDockingForm';  //if GetClassInfoEx(hInstance, PChar(szClassName), @wnd) then  //if GetClassInfoEx(Self.Handle, PChar(szClassName), @wnd) then  //szClassName := 'TTreeView';  //if GetClassInfoEx(TreeView1.Handle, PChar(szClassName), @wnd) then  begin    // Keep most properties untouched, let them as Get'ed    wnd.hbrBackground := HBRUSH(GetStockObject(NULL_BRUSH));    Windows.RegisterClassEx(wnd);  // Possible as update? To rewrite slightly modified information?  end;....  Doesn't succeed, GetClassInfoEx returns False, for form or control. No right idea yet. Maybe there are more correct approaches ... Besides that: somebody may wonder, why doesn't he apply the TWMEraseBkgnd interception technique to the treeview? That's already done. But has no effect here (in difference to a stand- alone exe): the code won't never be called. I would explain it by the fact that the class is already subclassed ("catched") by the Notepad++ plugin theme that takes over responsibility for (dark) background painting Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    SendMessage(Npp.NppData.NppHandle, NPPM_DARKMODESUBCLASSANDTHEME, DmFlag, Self.TreeView1.Handle);And so, for instance, i could, in a WndProc, breakpoint on WM_MOUSEWHEEL, but not on WM_ERASEBKGND. Normally, within other contexts, or the metadarkstyle layer, it has a good effect to proceed so, but not here. In the NPP plugin it doesn't seem to work. So:  as of now the most promising candidate seems to be for me the proposed code change in TCustomTreeView.UpdateHotTrack  ... ---------------------------------------------------------------------- 440bx · 2024-12-20 22:08 Now I remember the LCL does some "unusual" things with windows and that is likely the reason getting the class info doesn't work as expected. The LCL seems to often use a generic class named "Window" to route message processing to a generic window proc. The following example code gets the class name from any visible window.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE      GUI} {$LONGSTRINGS    OFF}{$WRITEABLECONST ON}{$DESCRIPTION    'Win32 API function - GetClassName example'} // {$R GetClassName.Res}  { left out } program _GetClassName;  { Win32 API function - GetClassName example                                 } uses Windows, Messages, Resource, SysUtils; const  AppNameBase  = 'GetClassName Example';   {$ifdef WIN64}    Bitness64  = ' - 64bit';    AppName    = AppNameBase + Bitness64;     { NOTE: also used as class name }  {$else}    Bitness32  = ' - 32bit';    AppName    = AppNameBase + Bitness32;  {$endif}   AboutBox     = 'AboutBox';  APPICON      = 'APPICON';  APPMENU      = 'APPMENU'; {------------------------------- ----------------------------------------------} {$ifdef VER90} { Delphi 2.0 }type  ptrint  = longint;  ptruint = dword;{$endif} {------ ---------------------------------------------------------------------- -} function About(DlgWnd : hWnd; Msg : UINT; wParam, lParam : ptrint)         : ptrint; stdcall;begin  About := ord(TRUE);   case msg of     WM_INITDIALOG: exit;     WM_COMMAND:    begin      if (LOWORD(wParam) = IDOK) or (LOWORD(wParam) = IDCANCEL) then      begin        EndDialog(DlgWnd, ord(TRUE));         exit;      end;    end;  end;   About := ord(FALSE);end; {-------------------------------------------- ---------------------------------} procedure DrawWindowFrame(Wnd : HWND);  { Draws a frame around the parameter Wnd                                  }var  dc         : HDC;  WindowRect : TRECT;   Pen        : HPEN;  OldPen     : HPEN; begin  { a 5 pixel wide pen is a reasonable choice. Some windows are "tucked" under}  { other child windows and a thin frame won't be visible because it falls    }  { in the "tucked" area.                                                   }   Pen := CreatePen(PS_INSIDEFRAME, 5, RGB(255, 0, 255));   GetWindowRect(Wnd, WindowRect);              { the window rectangle       }   {------------------------------------------------------------ ---------------}  { convert the coordinates in WindowRect to be relative to the upper left    }  { corner of the window.  At this time they are relative to the upper left   }  { corner of the screen.  After the conversion the (Left, Top) coordinate in }  { WindowRect will be (0, 0) which matches the preset (Left, Top) coordinate }  { the window dc.                                                          }   with WindowRect do OffsetRect(WindowRect, - Left, - Top);   {-- ---------------------------------------------------------------------- ---}  { we need a dc that doesn't clip the output to the client area and that can }  { be used to update a locked window (the window to be framed is locked).    }   dc :=  GetDCEx(Wnd,                 0,                    { no region                          }                 DCX_WINDOW       or                 DCX_CACHE        or               DCX_EXCLUDERGN   or     { excludes nothing because region = 0}               DCX_CLIPSIBLINGS or                 DCX_LOCKWINDOWUPDATE);   { select the pen and the brush used by the Rectangle API                  }   OldPen := SelectObject(dc, Pen);  SelectObject(dc, GetStockObject(NULL_BRUSH));  { only the frame gets drawn  }   { select a raster op that causes the original pixels to be restored when the}  { rectangle is drawn the second time.                                     }   SetROP2(dc, R2_NOTXORPEN);   {------------------------- --------------------------------------------------}  { draw a frame around (inside) the window rectangle                         }   with WindowRect do  begin    Rectangle(dc, Left, Top, Right, Bottom);  end;   SelectObject(dc, OldPen);          { restore the original pen             }  ReleaseDC(Wnd, dc);  DeleteObject(Pen);               { get rid of the pen                     }   {------------------------ ---------------------------------------------------}  { release the window dc                                                     }   ReleaseDC(dc, Wnd);end; {--------------------------------------------- --------------------------------} function WndProc (Wnd : hWnd; Msg : UINT; wParam, lParam : ptrint)         : ptrint; stdcall;  { main application/window handler function                                  }const  GetClassName_Call   = 'GetClassName (Wnd : HWND; NameBuf : pchar; BufSize : integer) : integer;';   FramedWindow         : hWnd = 0;   Tracking             : BOOL = FALSE;   Hint = 'Press the left mouse button - here - then move the mouse around'; var  ps               : TPAINTSTRUCT;   ClientRect         : TRECT;   Buf                : packed array[0..511] of char;  ClassName          : packed array[0..255] of char;   TextSize           : TSIZE;   MouseOnWindow    : HWND;  TopWindow          : HWND;  MousePt            : TPOINT; begin  WndProc := 0;   case Msg of    WM_LBUTTONDOWN:    begin      {---------------------------------------------------------- -------------}      { capture the mouse to make sure we always get the button up which      }      { is the signal to refresh the client area.                             }       SetCapture(Wnd);       {---- -------------------------------------------------------------------}    { if the window is partially covered by another window (like a menu)    }      { we want to make sure the window is fully uncovered before we draw     }      { the frame.  We do this using SetWindowPos and UpdateWindow.           }       SetWindowPos(Wnd,                 HWND_TOPMOST,                   0, 0, 0, 0,                   SWP_NOMOVE or SWP_NOSIZE or SWP_DRAWFRAME);      UpdateWindow(Wnd);       { it should be ok to draw the window frame now                        }       DrawWindowFrame(Wnd);      FramedWindow := Wnd;       Tracking := TRUE;                   { we are tracking the mouse       }       InvalidateRect(Wnd, nil, TRUE);      exit;    end;     WM_LBUTTONUP:    begin      {----------------------------------------- ------------------------------}      { Note that using "if GetCapture = Wnd" to find out if we are           }      { tracking the mouse can be a source of problems.  In some instances    }      { Windows (thru DefWindowProc) will capture the mouse for us, so        }      { having the mouse captured does not necessarily mean that we should    }      { draw or erase a frame.                                              }       if Tracking then      begin        ReleaseCapture;               { let the cat play with it            }         DrawWindowFrame(FramedWindow);  { erase the frame                     }        FramedWindow := -1;        Tracking     := FALSE;        LockWindowUpdate(0);         SetWindowPos(Wnd,                     HWND_NOTOPMOST,                     0, 0, 0, 0,                     SWP_NOMOVE or SWP_NOSIZE or SWP_DRAWFRAME);         InvalidateRect(Wnd, nil, TRUE); { redraw the client area              }      end;       exit;    end;     WM_MOUSEMOVE:    begin      { if we are not tracking the mouse then there's nothing to do           }       if not Tracking then exit;       { we don't use the coordinates stored in the lParam because they are    }      { in client coordinates and may not reflect the current position of     }      { the mouse if the user moved it after this message was received.       }       GetCursorPos(MousePt);       { get the handle of the window under the cursor                         }       MouseOnWindow := WindowFromPoint(MousePt);       if MouseOnWindow = FramedWindow then exit;  { previously framed         }       { The mouse is on a new window. Erase the previous frame                }       DrawWindowFrame(FramedWindow);      LockWindowUpdate(0);             { unlock it                            }      UpdateWindow(FramedWindow);      { let any pending updates thru       }       {------------------------------------------------------------ -----------}      { check that the window handle obtained is valid.  Just in case this    }      { is one of these windows that "come and go" (timed popups and such)    }       { following comment applies to Win9x only:                              }       { NOTE: strictly speaking we should acquire the Win16Mutex to make      }      {       sure that the window isn't going to disappear before we         }    {       attempt to frame it.                                          }       if not IsWindow(MouseOnWindow) then      begin        FramedWindow := -1;         exit;      end;       { draw the frame around the window. Because we did not acquire the      }      { Win16Mutex there is a _very_ slim chance that the window handle       }      { may no longer be valid.  We'll live with that possibility for this    }      { example.                                                            }       { tell the window to update itself before we lock it.  This prevents    }      { framing half painted windows. Unfortunately this produces flicker     }      { when the mouse is on windows that paint themselves periodically       }      { such as the System Monitor.  The flicker can be eliminated by         }      { always locking the Top Level window instead of the child window.      }       TopWindow := MouseOnWindow;      while GetParent(TopWindow) <> 0 do TopWindow := GetParent(TopWindow);       UpdateWindow(MouseOnWindow);       if MouseOnWindow <> Wnd then LockWindowUpdate(TopWindow);   { lock it   }      DrawWindowFrame(MouseOnWindow);                             { frame it  }       { we should release the Win16Mutex here if we had obtained it.          }      {------------------------------------------------- ----------------------}       { keep track of the currently framed window.                            }       FramedWindow := MouseOnWindow;       { update our display to reflect the window size of the new window       }       InvalidateRect(Wnd, nil, TRUE);       exit;    end;     WM_PAINT:    begin      BeginPaint(Wnd, ps);       GetClientRect(Wnd, ClientRect);       SetBkMode(ps.hdc, TRANSPARENT);      SetTextAlign(ps.hdc, TA_CENTER or TA_BOTTOM);      SelectObject(ps.hdc, GetStockObject(ANSI_VAR_FONT));       if Tracking then      begin        {---------------------------------------------- -----------------------}        { show the window handle the mouse is currently on                    }         GetClassName(FramedWindow, ClassName, sizeof(ClassName));        StrFmt(Buf, 'Class Name: "%s"', [ClassName]);      end      else      begin        {------------------ ---------------------------------------------------}        { give the user a hint about what to do next                          }         lstrcpy(Buf, Hint);      end;       TextOut(ps.hdc,              ClientRect.Right   div 2,              ClientRect.Bottom  div 2,            Buf,              lstrlen(Buf));       {----------------------- ------------------------------------------------}      { draw the function call                                                }        SelectObject(ps.hdc, GetStockObject(DEFAULT_GUI_FONT));      lstrcpy(Buf, GetClassName_Call);       { calculate the size of the output string                               }       GetTextExtentPoint32(ps.hdc,                           Buf,                         lstrlen(Buf), TextSize);       TextOut(ps.hdc,            ClientRect.Right div 2,              ClientRect.Bottom - TextSize.cy,              Buf,              lstrlen(Buf));       {---- -------------------------------------------------------------------}    { we're done painting                                                 }       EndPaint(Wnd, ps);       exit;    end;     WM_COMMAND:    begin      case LOWORD(wParam) of        IDM_ABOUT:        begin        DialogBox(hInstance, ABOUTBOX, Wnd, @About);           exit;      end; { IDM_ABOUT }         IDM_EXIT:        begin          DestroyWindow(Wnd);           exit;        end; { IDM_EXIT }      end; { case LOWORD(wParam) }    end; { WM_COMMAND }     WM_DESTROY:    begin       PostQuitMessage(0);       exit;    end; { WM_DESTROY }  end; { case msg }   WndProc := DefWindowProc (Wnd, Msg, wParam, lParam );end; {-------------------------------------------------------------- ---------------} function InitAppClass: WordBool;  { registers the application's window classes                                }var  cls : TWndClassEx; begin  cls.cbSize          := sizeof(TWndClassEx);       { must be initialized   }   if not GetClassInfoEx (hInstance, AppName, cls) then  begin    with cls do    begin      { cbSize has already been initialized as required above                 }       style           := CS_BYTEALIGNCLIENT;      lpfnWndProc     := @WndProc;                    { window class handler  }      cbClsExtra      := 0;      cbWndExtra      := 0;      hInstance       := system.hInstance;            { qualify instance!     }      hIcon         := LoadIcon (hInstance, APPICON);      hCursor         := LoadCursor(0, idc_arrow);      hbrBackground   := GetSysColorBrush(COLOR_WINDOW);      lpszMenuName    := APPMENU;                   { Menu name             }      lpszClassName   := AppName;                     { Window Class name     }      hIconSm       := LoadImage(hInstance,                                   APPICON,                                   IMAGE_ICON,                                 16,                                   16,                                 LR_DEFAULTCOLOR);    end; { with }     InitAppClass := WordBool(RegisterClassEx(cls));  end  else InitAppClass := True;end; {------------------------------------------- ----------------------------------} Function WinMain : integer;  { application entry point                                                 }var  Wnd : hWnd;  Msg : TMsg;begin  if not InitAppClass then Halt (255);  { register application's class        }   { Create the main application window                                        }   Wnd := CreateWindowEx(WS_EX_CLIENTEDGE,                        AppName,              { class name                  }                        AppName,                { window caption text         }                      ws_Overlapped       or  { window style                }                      ws_SysMenu          or                        ws_MinimizeBox      or                        ws_ClipSiblings     or                      ws_ClipChildren     or  { don't affect children     }                        ws_visible,             { make showwindow unnecessary }                        50,                     { x pos on screen             }                        50,                   { y pos on screen             }                        400,                  { window width                }                        300,                  { window height               }                      0,                      { parent window handle        }                      0,                      { menu handle 0 = use class   }                      hInstance,              { instance handle             }                        Nil);                   { parameter sent to WM_CREATE }   if Wnd = 0 then Halt;                         { could not create the window }   while GetMessage (Msg, 0, 0, 0) do          { wait for message            }  begin    TranslateMessage (Msg);                   { key conversions             }    DispatchMessage  (Msg);                     { send to window procedure    }  end;   WinMain := Msg.wParam;                        { terminate with return code  }end; begin  WinMain;end.Note that I left out the resource file (in line 7) but that should not affect how the program works.  With that code you'll at least know what the class name is. Also to compile this code (GetClassName.lpr) tell Lazarus it is a "simple program" (don't use any other option.) ---------------------------------------------------------------------- d7_2_laz · 2024-12-20 22:49 Oh thanks 440bx. As this did remind me on the old MS tool Spy++, i did a quick check with this, and indeed .. 'Window' (see screenshot) (independent from if form or any control are focused). So, one step forward. The If-code will be executed. But it hasn't any effect yet. The current value for hbrBackground is 0, that might possibly not be correct. (?) For comparison, lpszClassName (before assignment, only for inspecting:) is 'Window', so this matches the really existing value. Maybe the renewed 'RegisterClassEx' is an inappropriate call for to update a elass information ? ---------------------------------------------------------------------- 440bx · 2024-12-20 23:33 It looks like setting the class background brush to a null brush does not "fit" well in the LCL. Since I know next to nothing about the LCL, I have nothing else to offer. ---------------------------------------------------------------------- d7_2_laz · 2024-12-21 10:11 Ok 440bx, but i'd like to remark that there might be also some other reasons possible: - The subclassing NPP theme layer had already picked up the ownership of the drawing - the null_brush works for the form, but this is not noticeable (no form's flicker before, and not after). But the treeview flicker continues  because it's Invalidates causes control's repaint in light - RegisterClassEx is not designed for/not able to have an update capability - Within FormCreate it is done too late For to come nearer, some checks: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   wnd.hCursor := Windows.LoadCursor(0, IDC_WAIT); // This should directly be visible on the form ..  anAtom := Windows.RegisterClassEx(wnd);No effect. 'anAtom' is 0. It should contain a unique id for the class, so '0' is probably wrong. That does mean imo, no modification of the class attributes had happened. So it's not likely it's about the NULL_BRUSH only. Next checks: - try to do it at an earlier stage (CreateWnd): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   protected    procedure CreateParams(var Params: TCreateParams); override;    procedure CreateWnd; override; procedure THelloWorldDockingForm.CreateWnd;var wnd: Windows.TWNDClassEx; szClassName: String; anAtom: ATOM;begin  inherited CreateWnd;  szClassName := 'Window';  if GetClassInfoEx(hInstance, PChar(szClassName), @wnd) then  begin    wnd.hCursor := Windows.LoadCursor(0, IDC_WAIT);    anAtom := Windows.RegisterClassEx(wnd); // After that, 'anAtom' is 0.  end;end; No change of the cursor. - Now, an attempt using CreateParams, where one can influence styles: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure THelloWorldDockingForm.CreateParams(var Params: TCreateParams);begin  //inherited CreateParams(Params);  with Params do begin       //Style := Style or WS_BORDER;       //ExStyle := WS_EX_TOOLWINDOW or WS_EX_TOPMOST;       //WindowClass.Style := CS_SAVEBITS;       WindowClass.hbrbackground := HBRUSH(GetStockObject(NULL_BRUSH));;     WindowClass.hCursor := Windows.LoadCursor(0, IDC_WAIT);  end;  inherited CreateParams(Params);end; No wait cursor for the form, and no reduction of the treeview's flicker. I'll give up this way and go back to observe if i see side-effects of the proposed code change in TCustomTreeView.UpdateHotTrack next days. ---------------------------------------------------------------------- 440bx · 2024-12-21 11:05 I see a problem in the code you showed, the size field of the wndclassex structure has not been initialized as required. That will cause the registration to fail. see https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns- winuser-wndclassexa for details. HTH. ---------------------------------------------------------------------- d7_2_laz · 2024-12-21 11:58 Ok, good point!, as they say "set this member before calling the GetClassInfoEx function" So: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   szClassName := 'Window';  wnd.cbSize := SizeOf(TWndClassEx);  if GetClassInfoEx(hInstance, PChar(szClassName), @wnd) then begin     wnd.hbrBackground := HBRUSH(GetStockObject(NULL_BRUSH));     wnd.hCursor := Windows.LoadCursor(0, IDC_WAIT);     anAtom := Windows.RegisterClassEx(wnd);  end;-> anAtom stays '0'; no wait cursor to see  .. For to see, if the WinApi demo program 'StretchBlt' would allow at all to do a second call of RegisterClassEx, i did the following check - > see screenshot. ---------------------------------------------------------------------- 440bx · 2024-12-21 12:13 I've never tried registering a class more than once.  Windows probably considers that an error, you should use GetLastError to find out why the call failed. Also, once a class is registered, changing any of its "characteristics" is done using SetClassLong.  Read about it at https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf- winuser-setclasslonga You should use SetClassLongPtr but read the above linked page first. ---------------------------------------------------------------------- d7_2_laz · 2024-12-21 12:53 With GetLastError I was just about     -> image.  -  As expected ... 'SetClassLongPtrW' might be a promising pointer, possibly something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     //SetClassLongPtrW(hInstance, GCL_HBRBACKGROUND, 0);    //SetClassLongPtrW(Self.handle, GCL_HBRBACKGROUND, 0);    //SetClassLongPtrW(Treeview1.handle, GCL_HBRBACKGROUND, 0);    //SetClassLongPtrW(Self.Handle, GCL_HBRBACKGROUND, COLOR_BACKGROUND);    //SetClassLongPtrW(TreeView1.Handle, GCL_HBRBACKGROUND, COLOR_BACKGROUND);     SetClassLongPtrW(hInstance, GCL_HBRBACKGROUND, HBRUSH(GetStockObject(NULL_BRUSH)));    SetClassLongPtrW(Self.Handle, GCL_HBRBACKGROUND, HBRUSH(GetStockObject(NULL_BRUSH)));    SetClassLongPtrW(Treeview1.handle, GCL_HBRBACKGROUND, HBRUSH(GetStockObject(NULL_BRUSH)));    // or:    SetClassLongPtrW(Treeview1.handle, GCL_HBRBACKGROUND, LONG_PTR(GetStockObject(NULL_BRUSH))); (I remember i had used this once, ages ago, but only for the light theme, it hadn't played very well together with metadarkstyle) Within the plugin demo dockingform, dark, it has no visible effect for me. ---------------------------------------------------------------------- d7_2_laz · 2024-12-22 09:59 Now back to the code change proposal. Due to daily practice i've improved it a bit, as that's better for a rare use case where it should painted although the cursor is in a line in a x-pos right after a node's caption. This one would not be fully fetched by: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   FNodeUnderCursor := GetNodeAt(X, Y);If the cursor is after ending of the node's caption, a redraw won't be triggered. That should happen also when the cursor is within a line, not only within a caption text. But: principle is: i never wont't touch FNodeUnderCursor itself, for not to touch the used behaviour of drag & drop, no way. So, a local variable is needed. Compared with the situation before (Invalidate all) it doesn't play a role at all. It's simply a little bit more where InvalidateRect will be triggered. Another point: one may argue: and what's about MultiSelect? Ok, then ('for paranoia') do conventional behavior: Invalidate. Otherwise, please note: possibly only two lines are affected, Where the cursor is, and where he was. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomTreeView.UpdateHotTrack(X, Y: Integer);var aNode, nodeUnderCursorY: TTreeNode; R: TRect; previdx: Integer;begin.......  FNodeUnderCursor := GetNodeAt(X, Y);.......  // Invalidate;    // Not so global please - invalidae only the affected lines (at least if not MultiSelect)   if Self.MultiSelect then    Invalidate  else begin    nodeUnderCursorY := GetNodeAtY(Y);  // Instead of GetNodeAt(X, Y) FNodeUnderCursor. Don't want to touch FNodeUnderCursor itself!    previdx := FHotTrackedIdxPrevNode;    if FHotTrackedIdxPrevNode > -1 then begin      aNode := Items[FHotTrackedIdxPrevNode];      if (Assigned(aNode) And aNode.Visible) then begin        R := aNode.DisplayRect(False);        InvalidateRect(Handle, @R, True);    end;      FHotTrackedIdxPrevNode := -1;    end;    if Assigned(nodeUnderCursorY) then begin      R := nodeUnderCursorY.DisplayRect(False);      if not (previdx = nodeUnderCursorY.AbsoluteIndex) then // Not call InvalidateRect twice for the same item        InvalidateRect(Handle, @R, True);      FHotTrackedIdxPrevNode := nodeUnderCursorY.AbsoluteIndex;    end;  end; ---------------------------------------------------------------------- d7_2_laz · 2025-01-01 09:42 I'd opened an item in the bugtracker https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/41290 and a lately found little update preventing an additional condition about "not call InvalidateRect twice for the same item". ---------------------------------------------------------------------- d7_2_laz · 2025-01-20 11:13 Fix available in 'main' (and expected for Fixes_4)  https://gitlab.com/freepascal.org/lazarus/lazarus/- /commit/e897d845eafc7406b0a8b901f62aeea046097f9c ---------------------------------------------------------------------- d7_2_laz · 2025-01-27 21:15 It's in Fixes_4 and so either in an 4.0 RC3 or 4.0.