Einzelnen Beitrag anzeigen

flashcoder

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

AW: MagSetWindowFilterList function not remove specified window of screenshot

  Alt 29. Jan 2018, 07:20
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;
Angehängte Dateien
Dateityp: zip Magnification DEMO 29 - 01 - 2018.zip (93,8 KB, 25x aufgerufen)
  Mit Zitat antworten Zitat