Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Einzelnes StatusPanel neu zeichnen (https://www.delphipraxis.net/215863-einzelnes-statuspanel-neu-zeichnen.html)

Amateurprofi 19. Sep 2024 00:12

Einzelnes StatusPanel neu zeichnen
 
Wie kann ich bewirken, dass ein einzelnes Panel einer StatusBar neu gezeichnet wird.
Eine Möglichkeit, die ich sehe ist:
Delphi-Quellcode:
PROCEDURE RepaintPanel(StatusBar:TStatusBar; Index:Integer);
var Rect:TRect; Panel:TStatusPanel;
begin
   Panel:=StatusBar.Panels[Index];
   SendGetStructMessage(StatusBar.Handle, SB_GETRECT,Index,Rect);
   StatusBar.Canvas.Brush.Color:=StatusBar.Color;
   StatusBar.Canvas.FillRect(Rect);
   case Panel.Bevel of
      pbLowered  : Frame3D(StatusBar.Canvas,Rect,clGray,clWhite,1);
      pbRaised   : Frame3D(StatusBar.Canvas,Rect,clWhite,clGray,1);
   end;
   StatusBar.Canvas.Font:=StatusBar.Font;
   StatusBar.OnDrawPanel(StatusBar,Panel,Rect);
end;
Ich kann mir aber vorstellen, dass es eine simplere Möglichkeit gibt, z.B.
Delphi-Quellcode:
SendMessage(StatusBar.Handle,??,??,??);

Kas Ob. 19. Sep 2024 08:55

AW: Einzelnes StatusPanel neu zeichnen
 
Very interesting question, and i liked it !

From what i see, you have two option either
1) WM_DRAWITEM as it sound strange but many of these are not documented or the documentation is not clear,
https://learn.microsoft.com/en-us/wi...ls/wm-drawitem
But that page doesn't mention Status Bars, with this older version documentation
https://github.com/MicrosoftDocs/win...wn-status-bars
a detail explain on how to use it, notice that SB_XXX message are not supported on older Windows, but WM_DRAWITEM will work with them all Windows versions.

2) InvalidateRect , This one is my best choice, yet i have no idea if it is still working as intended on latest Windows with Status Bars (as for other (1) it is working and will work forever),
InvalidateRect is different, as it schedule the paint of the rectangle instead forcing an immediate draw, meaning it is fast and and the draw will happen on the next WM_PAINT, so you can over-call it with much less performance consequences, as the OS will handle the intersections as it see fit, while next WM_PAINT will do the perfect job.
https://learn.microsoft.com/en-us/wi...invalidaterect
yet again, you need to understand how fast it in signaling repaint and when it will happen, so it might or might-not fit your need, also InvalidateRect is the best companion for double buffering, to reduce flickering.

These what comes to mind as i recall them working, there is other approaches though, but need a recall and tests.

Amateurprofi 19. Sep 2024 14:49

AW: Einzelnes StatusPanel neu zeichnen
 
Liste der Anhänge anzeigen (Anzahl: 2)
Thank you Kas Op.

InvalidateRect
is not applicable for my purposes because I need the repainting immediately.

WM_DrawItem
Interesting.
However the part with the DRAWITEMSTRUCT sounds a bit complex (for me) (Pic1.jpg).
Seems that needs comparable efforts as my Procedure.
Just for Info:
In my StatusBar I can drag a panel to certain other positions, and I draw the dragged panel with different colors compared to other panels (Pic2.jpg).

Kas Ob. 19. Sep 2024 17:55

AW: Einzelnes StatusPanel neu zeichnen
 
Zitat:

Zitat von Amateurprofi (Beitrag 1541219)
Thank you Kas Op.

InvalidateRect
is not applicable for my purposes because I need the repainting immediately.

WM_DrawItem
Interesting.
However the part with the DRAWITEMSTRUCT sounds a bit complex (for me) (Pic1.jpg).
Seems that needs comparable efforts as my Procedure.
Just for Info:
In my StatusBar I can drag a panel to certain other positions, and I draw the dragged panel with different colors compared to other panels (Pic2.jpg).

I don't see theming or skinning involved in the Pic2, and that means you have an advantage of using the timer at 20ms which most likely will be between 20ms-31ms, if you send WM_PAINT to the status bar by timer with InvalidateRect, you will not see any noticeable CPU usage.
My reason here is that you have many parts and combining them all in one draw is the best, and also the timer will ensure the update close to 60hz and will be smooth without affecting the overall performance, and that of course if you are not doing heavy processing/logic when custom draw is invoked.

Amateurprofi 19. Sep 2024 22:04

AW: Einzelnes StatusPanel neu zeichnen
 
Again thank you Kas OP.
Works perfectly.


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz