Recent

Author Topic: [Solved]Desktop ScreenShot  (Read 7812 times)

codeman

  • Jr. Member
  • **
  • Posts: 78
[Solved]Desktop ScreenShot
« on: October 12, 2012, 09:19:51 pm »
Can i get a ScreenShot of my Desktop using PostMessage ?
Code: [Select]
PostMessage(0,WM_KEYDOWN,VK_Snapshot,0);
PostMessage(0,WM_KEYUP,VK_Snapshot,0);


Secondly , this code gives me a black ScreenShot image ... ?
Code: [Select]
bmp := TBitmap.Create;
bmp.Height := Screen.Height;
bmp.Width := Screen.Width;
DCDesk := GetWindowDC(GetDesktopWindow);
BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,DCDesk, 0, 0, SRCCOPY);
bmp.SaveToFile('ScreenShot.bmp');
ReleaseDC(GetDesktopWindow, DCDesk);
bmp.Free;
« Last Edit: October 13, 2012, 02:10:17 pm by codeman »
Lazarus v2.02 Win10

Laksen

  • Hero Member
  • *****
  • Posts: 785
    • J-Software
Re: Desktop ScreenShot
« Reply #1 on: October 12, 2012, 11:52:13 pm »
Try this
BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,DCDesk, 0, 0, SRCCOPY or CAPTUREBLT);

codeman

  • Jr. Member
  • **
  • Posts: 78
Re: Desktop ScreenShot
« Reply #2 on: October 13, 2012, 12:36:40 am »
Try this
BitBlt(bmp.Canvas.Handle, 0, 0, Screen.Width, Screen.Height,DCDesk, 0, 0, SRCCOPY or CAPTUREBLT);

I get compile error : Identifier not found "CAPTUREBLT"
Lazarus v2.02 Win10

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Desktop ScreenShot
« Reply #3 on: October 13, 2012, 12:40:03 am »
Code: Pascal  [Select][+][-]
  1. Procedure SaveScreenShot(const aFile:string);
  2. var
  3.   vBMP:TBitmap;
  4.   vDC : HDC;
  5. begin
  6.   vBMP:=TBitmap.Create;
  7.   vDC := GetDC(0);
  8.   vBMP.LoadFromDevice(vDC);
  9.   vBmp.SaveToFile(aFile);
  10.   ReleaseDC(0,vDC);
  11. end;
  12.  

One drawback it does not capture the program that executed the procedure in the screenshot,
I do not know if this can be overcome or not.

EDIT:
Tested it on windows 7 32bit using GTK2 as my widget set. So it is probably cross platform too.

Regards
Jo.
« Last Edit: October 13, 2012, 12:42:41 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Desktop ScreenShot
« Reply #4 on: October 13, 2012, 12:49:10 am »
@codeman

Try to "find in files" the constant CAPTUREBLT.

codeman

  • Jr. Member
  • **
  • Posts: 78
Re: Desktop ScreenShot
« Reply #5 on: October 13, 2012, 02:09:08 pm »

One drawback it does not capture the program that executed the procedure in the screenshot,
I do not know if this can be overcome or not.

Thanks @taazz
About the drawback you said , it does not capture it only if i call the procedure onCreate or onActivate , btw i can handle this with a timer : )
« Last Edit: October 13, 2012, 02:20:37 pm by codeman »
Lazarus v2.02 Win10

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: [Solved]Desktop ScreenShot
« Reply #6 on: October 13, 2012, 03:36:47 pm »
Maybe its a GTK behavior I do not know my test where done with a button and its click event.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018