Recent

Author Topic: [Solved] Trackbar flickering  (Read 6148 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: Trackbar flickering
« Reply #15 on: March 05, 2024, 04:42:26 pm »
or
Code: Pascal  [Select][+][-]
  1. var vRect : windows.Trect
rest looks fine.
« Last Edit: March 05, 2024, 04:43:59 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 649
Re: Trackbar flickering
« Reply #16 on: March 05, 2024, 05:08:19 pm »
Thaddy thanks, that’s true too  :)  (i remember a bit of philosophical debate about somewhere else: “prefix it” vs. “change the order of units”).
Joanna: mine was from “Classes”,  which allows such a constructor as used. The other is from “Windows”, which does not.
A change of ordering might have impact elsewhere, so the prefixing is more sure. Sure as a direct assignment …
Lazarus 4.4  FPC 3.2.2 Win10 64bit

Joanna

  • Hero Member
  • *****
  • Posts: 1401
Re: Trackbar flickering
« Reply #17 on: March 06, 2024, 12:18:39 am »
Thanks everyone for the advice
I put the windows first in the uses section and it finally compiled.
Unfortunately the trackbar wiggles when resized.  :(
I’m wondering if I should try just hiding it while it’s being resized..

Nope that didn’t help either. It must be the win 7 operating system at fault.
Hopefully flickering will go away if I ever manage to port this to other platforms.
« Last Edit: March 06, 2024, 02:30:15 am by Joanna »

440bx

  • Hero Member
  • *****
  • Posts: 5896
Re: Trackbar flickering
« Reply #18 on: March 06, 2024, 02:41:11 am »
Nope that didn’t help either. It must be the win 7 operating system at fault.
Just for precision's sake...

It's extremely unlikely that the problem is in Win7, what's much more likely (read: extremely high probability) is that the trackbar implementation which is part of the Common Controls is buggy (not to mention poorly designed.)

As a historical note, in Win95, MS greatly extended the common controls, unfortunately it seems they gave the responsibility for implementing them to a group of high school students who had seen a computer in pictures only (and considering the result, the pictures were probably blurry!.)  The implementation was truly _sad_.  The library has improved over the years but, it still leaves a LOT  to desire and there are still plenty of "deficiencies" in it.  It's fairly obvious why Windows Explorer does not use the Common Controls instead it uses a custom implementation (much more capable and reliable.)

Anyway... the above is just FYI for whoever might be curious.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Joanna

  • Hero Member
  • *****
  • Posts: 1401
Re: [Explained] Trackbar flickering
« Reply #19 on: March 06, 2024, 02:50:15 am »
I’m not surprised, however I lack the knowledge of how to fix it. I believe that there is also a tcdtrackbar control I don’t know if it would work better or not.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 649
Re: [Explained] Trackbar flickering
« Reply #20 on: March 06, 2024, 09:45:17 pm »
Joanna, just a thought besides:
ok, probably pre-paint / erasebkgnd isn’t responsibly involved here.
But what if the prog or component is flooded by too many paintings, maybe due to too many resize messages (remember, what wp did said: it would occur also if the size of the trackbar is fix).
What does this little test app say?
(Idea behind: if yes (too many messages), there should be found a hook).

Btw: you said you tried by “hiding it while it’s being resized”. -> How did you detect a “resize start” vs. a “resize end”?

EDIT: as a kind of reference, on Win10 i see such occurence of size/erase/paint messages as shown in the screenshot (having the trackbar aligned).


« Last Edit: March 06, 2024, 09:51:26 pm by d7_2_laz »
Lazarus 4.4  FPC 3.2.2 Win10 64bit

lainz

  • Hero Member
  • *****
  • Posts: 4738
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: [Explained] Trackbar flickering
« Reply #21 on: March 06, 2024, 10:45:25 pm »
Try bgracontrols TBCTrackBarUpDown. Or custom drawn package...

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: [Explained] Trackbar flickering
« Reply #22 on: March 06, 2024, 11:53:17 pm »
Let me test two standard ways to reduce flicker:

When I take d7_2_laz's code and add "Message.Msg := 1" (or 0) to the WMEraseBkGnd handler, the flicker is gone, even on Win 7, for both aligned and unaligned cases:
Code: Pascal  [Select][+][-]
  1. procedure TTrackBar.WMEraseBkgnd(var Message: TLMEraseBkgnd);
  2. var aRect : TRect;
  3. begin
  4.   Message.Msg := 1;
  5. end;

An alternative possibility which seems to work in the same way is to override the CreateParams method and add a specific flag:
Code: Pascal  [Select][+][-]
  1. procedure TTrackbar.CreateParams(var Params: TCreateParams);
  2. begin
  3.   inherited;
  4.   Params.ExStyle := Params.ExStyle or $02000000;
  5. end;

And finally, without using a sub-classed TTrackbar, this code basically could be added to the win32 interface:
Code: Pascal  [Select][+][-]
  1. class function TWin32WSTrackBar.CreateHandle(const AWinControl: TWinControl;
  2.   const AParams: TCreateParams): HWND;
  3. var
  4.   Params: TCreateWindowExParams;
  5. begin
  6.   // general initialization of Params
  7.   PrepareCreateWindow(AWinControl, AParams, Params);
  8.   // customization of Params
  9.   with Params do
  10.   begin
  11.     pClassName := TRACKBAR_CLASS;
  12.     WindowTitle := StrCaption;
  13.     FlagsEx := FlagsEx or $02000000;
  14.   end;
  15.   // create window
  16.   FinishCreateWindow(AWinControl, Params, false);
  17.   Params.WindowInfo^.ParentMsgHandler := @TrackBarParentMsgHandler;
  18.   Params.WindowInfo^.ThemedCustomDraw := true;
  19.   Result := Params.Window;
  20. end;
This procedure is in file lcl\interfaces\win32\win32wscomctrls.pp of your Lazarus installation. Add the highlighted line, and recompile your project (but before changing any lazarus file, always make a backup copy). I would appreciate if in particular the last method would be tested (for me it is working on Win 11 and Win 7 and does not seem to have side-effects).
« Last Edit: March 07, 2024, 12:35:55 am by wp »

jamie

  • Hero Member
  • *****
  • Posts: 7405
Re: [Explained] Trackbar flickering
« Reply #23 on: March 07, 2024, 12:42:15 am »
WS_EX_COMPOSITED

That is a double buffer flag for a window, not supported in W2k, which people still use and I am not sure what effects it would have.

 Why not have a DoubleBuffer property in the control incase this does not work in all cases ?
The only true wisdom is knowing you know nothing

d7_2_laz

  • Hero Member
  • *****
  • Posts: 649
Re: [Explained] Trackbar flickering
« Reply #24 on: March 07, 2024, 10:09:04 am »
WS_EX_COMPOSITED (0x02000000) – maybe DoubleBuffer hadn’t come into effect here without this flag; see:  https://devblogs.microsoft.com/oldnewthing/20171018-00/?p=97245

wp, I was somehow surprised that it helped here … being interested to know if without the “Exit(True)” (0 or 1, both seen as True? = “Windows, don’t paint, I’ll do this myself”) the amount of event calls was comparable. Could you tell or give a screenshot?
(On Win10 it had behaved fully normal, so I cannot see)
--
I’ ll try the change of the win32 interface later the day for to see if I notice a caveat.
« Last Edit: March 07, 2024, 10:26:46 am by d7_2_laz »
Lazarus 4.4  FPC 3.2.2 Win10 64bit

Joanna

  • Hero Member
  • *****
  • Posts: 1401
Re: [Explained] Trackbar flickering
« Reply #25 on: March 07, 2024, 02:37:47 pm »
Thanks for the answers ?
Are any of the solutions cross platform without a dependency on the windows unit though?

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: [Explained] Trackbar flickering
« Reply #26 on: March 07, 2024, 03:58:54 pm »
So far, the flicker was reported by you only for Windows (7). It is not clear at all whether the Trackbars on other platforms is flickering as well.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 649
Re: [Explained] Trackbar flickering
« Reply #27 on: March 07, 2024, 06:16:22 pm »
Sorry for the interrupt, short break back to the windows patch:
@wp, I tried your fix proposal on file lcl\interfaces\win32\win32wscomctrls.pp with Laz 3.0 Win64.
I couldn’t see any negative impacts as of now.
Also no benefits, of course, as there hadn’t be a negative behavior before …

But – just as one could expect, case trackbar not aligned – regarding the messages flow, after form’s resize there are no longer any trackbar’s resize/erasebkgnd/paint messages     // see image
Of course, if trackbar is aligned, a form’s resize will be followed by trackbar resize etc. -  All just as it should be …..

Btw, would interest me: in the OS scenario where the flicker had been seen:
before the fix, did you notice any strange message dispatching, an unexpected amount of resize/erasebkgnd/paint messages that differed noticeably from my first screenshot?

Lazarus 4.4  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: [Explained] Trackbar flickering
« Reply #28 on: March 07, 2024, 07:44:53 pm »
Btw, would interest me: in the OS scenario where the flicker had been seen:
before the fix, did you notice any strange message dispatching, an unexpected amount of resize/erasebkgnd/paint messages that differed noticeably from my first screenshot?
No, nothing special, almost no change to the non-flickering Win11 (one more EraseBkGnd). The screenshots were taken after clearing the memo and clicking the button to increase the form width by 1. I set the Trackbar's Color to yellow to see that the background color in unthemed mode is still working after the patch - yes.

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: [Explained] Trackbar flickering
« Reply #29 on: March 07, 2024, 07:47:19 pm »
Here are the screenshots for the same condition after the patch (could not send them in the previous post due to forum restrictions)

(Just to explain: Win 7 is flickering before the patch, Win 11 never; and "patch" refers to the change in TWin32WSTrackBar shown above).
« Last Edit: March 07, 2024, 07:54:18 pm by wp »

 

TinyPortal © 2005-2018