![]() |
Delphi-Version: 10 Seattle
How elimitnate flicker of Form on resizing?
Liste der Anhänge anzeigen (Anzahl: 1)
I have this code below where is possible see desktop behind a full screen Form and have a trouble of flicker every time that Form is resized on these lines:
Delphi-Quellcode:
How prevent this flicker?
procedure TForm1.TakeScreenShot;
begin Width := 0; Height := 0; DoSnapShot := True; Width := ScreenRect.Width; Height := ScreenRect.Height; end; Thanks in advance Full code:
Delphi-Quellcode:
PS: BorderStyle property is bsNone
type
TForm1 = class(TForm) CAPTURAR: TButton; SAIR: TButton; procedure FormCreate(Sender: TObject); procedure CAPTURARClick(Sender: TObject); procedure SAIRClick(Sender: TObject); private DesktopBMP: TBitmap; DoSnapShot: boolean; ScreenRect: TRect; procedure TakeScreenShot; procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND; public { Public declarations } protected procedure Paint; override; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.CAPTURARClick(Sender: TObject); begin TakeScreenShot; end; procedure TForm1.FormCreate(Sender: TObject); begin Left := 0; Top := 0; Width := Screen.Width; Height := Screen.Height - 10; ScreenRect := Rect(Left, Top, Width, Height); DesktopBMP := TBitmap.Create; DesktopBMP.SetSize(Width, Height); end; procedure TForm1.Paint; begin inherited; // Canvas.Draw(0, 0, DesktopBMP); DesktopBMP.SaveToFile('c:\screen.bmp'); end; procedure TForm1.SAIRClick(Sender: TObject); begin Application.Terminate; end; procedure TForm1.TakeScreenShot; begin Width := 0; Height := 0; DoSnapShot := True; Width := ScreenRect.Width; Height := ScreenRect.Height; end; procedure TForm1.WMEraseBkgnd(var Message: TWMEraseBkgnd); var DesktopDC: HDC; DesktopHwnd: Hwnd; DesktopCanvas: TCanvas; begin if DoSnapShot then begin DoSnapShot := False; DesktopHwnd := GetDesktopWindow; DesktopDC := GetDC(DesktopHwnd); try DesktopCanvas := TCanvas.Create; DesktopCanvas.Handle := DesktopDC; DesktopBMP.Canvas.CopyRect(ScreenRect, DesktopCanvas, ScreenRect); finally DesktopCanvas.Free; ReleaseDc(DesktopHwnd, DesktopDC); end; end; Message.Result := 1; inherited; end; |
AW: How elimitnate flicker of Form on resizing?
Resizing the form will call your screenshot function multiple times within a very short time periode. The
Delphi-Quellcode:
/
CopyRect
Delphi-Quellcode:
screenshot method is not recommended on newer Windows versions, as this code is already very slow itself (this will copy the complete desktop contents from the video memory to the CPU memory every time). You might be able to reduce flickering by using some kind of double-buffering, but I would recommend you to use the
BitBlt
![]() |
AW: How elimitnate flicker of Form on resizing?
Zitat:
Delphi-Quellcode:
not works.
DoubleBuffered := True;
|
AW: How elimitnate flicker of Form on resizing?
Paint in Paint and ignore WMEraseBkgnd btw. result 1 and Exit.
greets |
AW: How elimitnate flicker of Form on resizing?
Zitat:
|
AW: How elimitnate flicker of Form on resizing?
using my Doublebuffer.
Delphi-Quellcode:
function TForm1.DoubleBuffer(DC: HDC; width, height: Integer; Action: TAction): HDC;
begin if Action = CreateBuffer then begin FDBufferhDCTemp := CreateCompatibleDC(DC); FDBufferhBMTemp := CreateCompatibleBitmap(DC, width, height); FDBufferhBMPrev := SelectObject(FDBufferhDCTemp, FDBufferhBMTemp); FDBufferXx := width; FDBufferYy := height; FDBufferUseDC := DC; Result := FDBufferhDCTemp; end else begin // Zeichne das Resultat ins Target Window BitBlt(FDBufferUseDC, width, height, FDBufferXx, FDBufferYy, FDBufferhDCTemp, 0, 0, SRCCOPY); // Befreie die system resourcen SelectObject(FDBufferhDCTemp, FDBufferhBMPrev); DeleteObject(FDBufferhBMTemp); DeleteDC(FDBufferhDCTemp); Result := 0; end; end; ![]() ![]() i am not use Doublebuffer from the Form it self. greets |
AW: How elimitnate flicker of Form on resizing?
Ok, but this way, Form will appear in screenshot, right?
|
AW: How elimitnate flicker of Form on resizing?
Zitat:
and then test it. i am use D2010 so can't not use your example.. sorry greets |
AW: How elimitnate flicker of Form on resizing?
Zitat:
|
AW: How elimitnate flicker of Form on resizing?
Zitat:
I not understood where use DC in my code
Delphi-Quellcode:
and also want know if these parameters passed to this custom DoubleBuffer function are of my Form in my situation?
var
DC: HDC; rc: TRect; begin rc := Form1.ClientRect; DC := DoubleBuffer(Form1.Canvas.Handle, rc.Right, rc.Bottom, CreateBuffer); // Where use this DC? end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:33 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 by Thomas Breitkreuz