![]() |
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; |
AW: How elimitnate flicker of Form on resizing?
i can not see any resize Event in your example
after create the form in Fullscreen so i not understand what your do. greets |
AW: How elimitnate flicker of Form on resizing?
Zitat:
Relative to my last answer, what component (in my case) i can apply custom DubleBuffer function? Ex: the parameters received are of my Form? could give a example about where apply this function? |
AW: How elimitnate flicker of Form on resizing?
Zitat:
i see a Fullscreen without drawing any and after can't resize the form. not understand how your see the flicker.. nothing is draw to the Fullscreen Window sorry for my bad english. Zitat:
if nothing paint on the fullcreen and i can not resize it. and you has a example see my Starwars Scrolltext, please compare if understand your code correctly then you create a CompatibleDC here.
Delphi-Quellcode:
that should be
DesktopCanvas := TCanvas.Create;
Delphi-Quellcode:
DesktopCanvas := DoubleBuffer(Form1.Canvas.Handle, rc.Right, rc.Bottom, CreateBuffer);
now draw to DesktopCanvas .. then use
Delphi-Quellcode:
DoubleBuffer(0, 0, 0, DestroyBuffer);
which bitblt your result to the Target window and free the ressources. greets |
AW: How elimitnate flicker of Form on resizing?
Unfortunately i not understood your custom DoubleBuffer function.
Probably this can work to remove flicker when Form is resized in TakeScreenshot method, but i'm totally lost about how implement on my code :( |
AW: How elimitnate flicker of Form on resizing?
Zitat:
Delphi-Quellcode:
check this works by me..
if DoSnapShot then
begin DoSnapShot := False; DesktopHwnd := GetDesktopWindow; DesktopDC := GetDC(DesktopHwnd); DesktopCanvas := DoubleBuffer(Canvas.Handle, ScreenRect.Right, ScreenRect.Bottom, CreateBuffer); BitBlt(DesktopCanvas, 0, 0, ScreenRect.Right, ScreenRect.Bottom, DesktopDC, 0, 0, SRCCOPY); DoubleBuffer(0, 0, 0, DestroyBuffer); ReleaseDc(DesktopHwnd, DesktopDC); end; EDIT: Your problem is not the flickering but the setting of the height and width to 0 and then back to the old Position (Fullscreen) Rethink your approach using.. "Hide, Show" or "minimize, maximize" or create a Container for the Capture. just a Suggestion. greets |
AW: How elimitnate flicker of Form on resizing?
Zitat:
this idea of container seems more appropiated for me, but my form still will appear on screenshot? I not want hide/show or minimoze/maximize, this not is good. Remember that background of Form must be erased before capture the screen. This container could be a TImage or what? |
AW: How elimitnate flicker of Form on resizing?
Zitat:
You change the size on every call that is wrong. (So you have to live with your current Situation) You do not want to hide that windows, that's wrong. (so the form is still appear) Unfortunately I can't help you anymore.. find your own way greets |
AW: How elimitnate flicker of Form on resizing?
Zitat:
|
AW: How elimitnate flicker of Form on resizing?
that works..
with my own way so you can see i have give you all required Information. bye. Anhang gelöscht. greets |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:36 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