AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi How elimitnate flicker of Form on resizing?
Thema durchsuchen
Ansicht
Themen-Optionen

How elimitnate flicker of Form on resizing?

Ein Thema von flashcoder · begonnen am 6. Feb 2018 · letzter Beitrag vom 9. Feb 2018
Antwort Antwort
Seite 1 von 2  1 2      
flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#1

How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 01:26
Delphi-Version: 10 Seattle
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:
procedure TForm1.TakeScreenShot;
begin
  Width := 0;
  Height := 0;
  DoSnapShot := True;
  Width := ScreenRect.Width;
  Height := ScreenRect.Height;
end;
How prevent this flicker?

Thanks in advance

Full code:

Delphi-Quellcode:
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;
PS: BorderStyle property is bsNone
Angehängte Dateien
Dateityp: zip test.zip (74,3 KB, 15x aufgerufen)

Geändert von flashcoder ( 6. Feb 2018 um 02:08 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#2

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 14:55
Resizing the form will call your screenshot function multiple times within a very short time periode. The CopyRect /BitBlt 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 Desktop Duplication API introduced in Windows 8.
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)
  Mit Zitat antworten Zitat
flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#3

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 18:09
Zitat von Zacherl:
You might be able to reduce flickering by using some kind of double-buffering.
DoubleBuffered := True; not works.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#4

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 18:31
Paint in Paint and ignore WMEraseBkgnd btw. result 1 and Exit.

greets
  Mit Zitat antworten Zitat
flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#5

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 18:49
Paint in Paint and ignore WMEraseBkgnd btw. result 1 and Exit.

greets
Also without success, could show how you made, please?
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#6

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 19:24
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;
and load as example
how do use it. see PaintBox1Paint

i am not use Doublebuffer from the Form it self.

greets

Geändert von EWeiss ( 6. Feb 2018 um 19:27 Uhr)
  Mit Zitat antworten Zitat
flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#7

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 19:40
Ok, but this way, Form will appear in screenshot, right?
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#8

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 19:44
Ok, but this way, Form will appear in screenshot, right?
why? read the example.
and then test it.

i am use D2010 so can't not use your example.. sorry

greets

Geändert von EWeiss ( 6. Feb 2018 um 19:48 Uhr)
  Mit Zitat antworten Zitat
flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#9

AW: How elimitnate flicker of Form on resizing?

  Alt 6. Feb 2018, 19:56
Ok, but this way, Form will appear in screenshot, right?
why? read the example.
and then test it.

i am use D2010 so can't not use your example.. sorry

greets
All functions used in my example are compatible with any delphi version from 2010 until 10 Berlin
  Mit Zitat antworten Zitat
flashcoder

Registriert seit: 10. Nov 2013
83 Beiträge
 
#10

AW: How elimitnate flicker of Form on resizing?

  Alt 7. Feb 2018, 23:14
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;
and load as example
how do use it. see PaintBox1Paint

i am not use Doublebuffer from the Form it self.

greets


I not understood where use DC in my code

Delphi-Quellcode:
var
 DC: HDC;
 rc: TRect;
begin

rc := Form1.ClientRect;
DC := DoubleBuffer(Form1.Canvas.Handle, rc.Right, rc.Bottom, CreateBuffer);

// Where use this DC?

end;
and also want know if these parameters passed to this custom DoubleBuffer function are of my Form in my situation?
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:15 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz