Delphi-PRAXiS
Seite 4 von 4   « Erste     234   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi MagSetWindowFilterList function not remove specified window of screenshot (https://www.delphipraxis.net/195027-magsetwindowfilterlist-function-not-remove-specified-window-screenshot.html)

EWeiss 29. Jan 2018 01:28

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Zitat:

Zitat von flashcoder (Beitrag 1392330)
Delphi is case insensitive and is able to know waht is a variable name and a type.

and that is a good code style?
i think not.

greets

Zacherl 29. Jan 2018 01:55

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Zitat:

Zitat von flashcoder (Beitrag 1392328)
Delphi-Quellcode:
MagSetWindowSource
not is necessary, i tested here (Delphi code) without this api and screenshot still is works.

It keeps crashing, if I comment out the
Delphi-Quellcode:
MagSetWindowSource
. Callstack points to `msvcrt.memcpi` so I guess there's something fishy somewhere else. Could be anything like wrong types, calling conventions, buffer overreads, ... Same problem might cause your black image. Buffer overreads/overflows can be tricky sometimes and do not always result in reproducable problems.

EWeiss 29. Jan 2018 05:40

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Zitat:

Zitat von Zacherl (Beitrag 1392332)
Zitat:

Zitat von flashcoder (Beitrag 1392328)
Delphi-Quellcode:
MagSetWindowSource
not is necessary, i tested here (Delphi code) without this api and screenshot still is works.

It keeps crashing, if I comment out the
Delphi-Quellcode:
MagSetWindowSource
. Callstack points to `msvcrt.memcpi` so I guess there's something fishy somewhere else. Could be anything like wrong types, calling conventions, buffer overreads, ... Same problem might cause your black image. Buffer overreads/overflows can be tricky sometimes and do not always result in reproducable problems.

the Trouble is resize, that is known on W7 64Bit.
but it works on W7 32 BIT.
i think you can nothing do on it.

greets

flashcoder 29. Jan 2018 06:20

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Liste der Anhänge anzeigen (Anzahl: 1)
Here is project solved and working 100% like must be.

Delphi-Quellcode:
var
  Form1: TForm1;

implementation

uses
  Unit3, Magnification;

{$R *.dfm}

function MagImageScalingCallback(hwnd: hwnd; srcdata: Pointer;
  srcheader: MAGIMAGEHEADER; destdata: Pointer; destheader: MAGIMAGEHEADER;
  unclipped: TRect; clipped: TRect; dirty: HRGN): BOOL; stdcall;
var
  lpbmi: TBitmapInfo;
  bmp: TBitmap;
  aDC: HDC;
  abitmap: HBitmap;
begin
  Fillchar(lpbmi, sizeof(lpbmi), 0);
  lpbmi.bmiHeader.biSize := sizeof(lpbmi.bmiHeader);
  lpbmi.bmiHeader.biHeight := -srcheader.height;
  // Otherwise the image is upside down.
  lpbmi.bmiHeader.biWidth := srcheader.width;
  lpbmi.bmiHeader.biSizeImage := srcheader.cbSize;
  lpbmi.bmiHeader.biPlanes := 1;
  lpbmi.bmiHeader.biBitCount := 32;
  lpbmi.bmiHeader.biCompression := BI_RGB;

  aDC := GetWindowDC(hwnd);
  bmp := TBitmap.Create;
  abitmap := 0;
  try
    abitmap := CreateDIBitmap(aDC, lpbmi.bmiHeader, CBM_INIT, srcdata, lpbmi,
      DIB_RGB_COLORS);
    bmp.handle := abitmap;
    bmp.SaveToFile('c:\screen.bmp');
  finally
    DeleteObject(abitmap);
    DeleteDC(aDC);
    bmp.Free;
  end;

  Result := True;
end;

procedure MagScreenShot;
var
  desktop, hwndMag: hwnd;
  desktoprect, sourceRect: TRect;
  filterList: THWNDArray;
  m_ScreenX, m_ScreenY, m_ScreenT, m_ScreenL: Integer;
begin

  Form1.WindowState := wsMaximized;

  if not Form3.Showing then
    Form3.Show;

  desktop := GetDesktopWindow;
  GetWindowRect(desktop, desktoprect);

  m_ScreenT := desktoprect.Top;
  m_ScreenL := desktoprect.Left;
  m_ScreenX := desktoprect.right;
  m_ScreenY := desktoprect.bottom;

  if (not MagInitialize) then
  begin
    Application.MessageBox('Init magnification failed', 'Error',
      mb_Ok + mb_IconError);
    Exit;
  end;

  hwndMag := CreateWindow(WC_MAGNIFIER, 'MagnifierWindow',
    WS_CHILD or MS_SHOWMAGNIFIEDCURSOR or WS_VISIBLE, 0, 0, m_ScreenX,
    m_ScreenY, Form1.handle, 0, hInstance, nil);

  if (hwndMag = 0) then
  begin
    Application.MessageBox('MagnifierWindow creation failed', 'Error',
      mb_Ok + mb_IconError);
    Exit;
  end;

  if (not MagSetImageScalingCallback(hwndMag, MagImageScalingCallback)) then
  begin
    Application.MessageBox('Cannot set callback', 'Error',
      mb_Ok + mb_IconError);
    Exit;
  end;

  try
    filterList[0] := Form3.handle;
  except
  end;

  if (not MagSetWindowFilterList(hwndMag, MW_FILTERMODE_EXCLUDE, 1,
    @filterList[0])) then
  begin
    Application.MessageBox('Cannot exclude main window', 'Error',
      mb_Ok + mb_IconError);
    Exit;
  end;

  sourceRect.Top := m_ScreenT;
  sourceRect.Left := m_ScreenL;
  sourceRect.right := m_ScreenX;
  sourceRect.bottom := m_ScreenY;

  Sleep(200);

  if (not MagSetWindowSource(hwndMag, sourceRect)) then
  begin
    Application.MessageBox('Cannot set source to MagnifierWindow', 'Error',
      mb_Ok + mb_IconError);
    Exit;
  end;

  { if (not MagUninitialize) then
    begin
    Application.MessageBox('Finalize magnification failed', 'Error',
    mb_Ok + mb_IconError);
    Exit;
    end; }
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
  MagScreenShot;
end;

Zacherl 29. Jan 2018 06:49

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Zitat:

Zitat von EWeiss (Beitrag 1392334)
Zitat:

Zitat von Zacherl (Beitrag 1392332)
Zitat:

Zitat von flashcoder (Beitrag 1392328)
Delphi-Quellcode:
MagSetWindowSource
not is necessary, i tested here (Delphi code) without this api and screenshot still is works.

It keeps crashing, if I comment out the
Delphi-Quellcode:
MagSetWindowSource
. Callstack points to `msvcrt.memcpi` so I guess there's something fishy somewhere else. Could be anything like wrong types, calling conventions, buffer overreads, ... Same problem might cause your black image. Buffer overreads/overflows can be tricky sometimes and do not always result in reproducable problems.

the Trouble is resize, that is known on W7 64Bit

Yes, I can confirm this. The latest version works for me, but resizing still crashes the application.

EWeiss 29. Jan 2018 07:37

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Zitat:

Here is project solved and working 100% like must be.
no it Crash.. and has a black Screen.
it works and does not work.

MagImageScalingCallback is not needed.
and if you deactivate Desktop Theme then it Crash always..
on this line

Delphi-Quellcode:
  if (not MagSetWindowSource(hwndMag, sourceRect)) then

with Floating Point invalid Operation.

here are a full new projekt
which works without Crash, please deactivate Desktop Themes before run.
sorry your source text is fully flawed.

1. Each new call creates a new instance of the Magnification Dll without uninitializing the old one before.
2. Each new call creates a new Window without destroy the old one before.
3. Array of tagMAGTRANSFORM is wrong.
4. Filterlist is not Needed.
5. a second form is not needed.
6. the callback also if your use a Timer.

.. and so on.

greets

flashcoder 29. Jan 2018 13:06

AW: MagSetWindowFilterList function not remove specified window of screenshot
 
Zitat:

Zitat von EWeiss (Beitrag 1392346)
Zitat:

Here is project solved and working 100% like must be.
no it Crash.. and has a black Screen.
it works and does not work.

MagImageScalingCallback is not needed.
and if you deactivate Desktop Theme then it Crash always..
on this line

Delphi-Quellcode:
  if (not MagSetWindowSource(hwndMag, sourceRect)) then

with Floating Point invalid Operation.

here are a full new projekt
which works without Crash, please deactivate Desktop Themes before run.
sorry your source text is fully flawed.

1. Each new call creates a new instance of the Magnification Dll without uninitializing the old one before.
2. Each new call creates a new Window without destroy the old one before.
3. Array of tagMAGTRANSFORM is wrong.
4. Filterlist is not Needed.
5. a second form is not needed.
6. the callback also if your use a Timer.

.. and so on.

greets

Even that your code work (and yes works with aero actived or no here), the approach of question is totally different of this and your last update is more near of this approach, but even thank you by fix some bugs mainly the and of your enumeration.

About item , is necessary because i not want show Magnifier window to user (i still will hide Form1 in my project), based on C++ example. Please, read item 2 on page of C++ example.

Relative to black screen, see in my last updated that is black only on Magnifier window, but on bmp file not.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:48 Uhr.
Seite 4 von 4   « Erste     234   

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