### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Recent

#### BenJones

• Full Member
• Posts: 121
« on: July 17, 2011, 05:21:57 pm »
Hi all I been racking my head for over an hour with this bit of code, I am trying to make a program to capture a screen shot of my desktop. but my code seems to be produceing a black image., the only way it works if I use text out and write some text on it then it saves ok but i do not want to really do that can someone please have a look at my code incase i done something wrong thanks.

Code: [Select]
`procedure TForm1.Button1Click(Sender: TObject);var  dc: HDC;  img: TImage;begin  //Get desktop window dc  dc := GetDc(GetDesktopWindow);  //Create the image  img := Timage.Create(self);  //set image width and height  img.Width := screen.Width;  img.Height := screen.Height;  //Hide form we do not want it included in our screeny  Form1.Visible := False;  sleep(500);  //Take screen shot of desktop window  BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height, dc, 0, 0, SRCCOPY);  //img.Canvas.TextOut(90,0,'Screeny shot by ben');  //save the image  img.Picture.SaveToFile('c:\out\benny.bmp');  //Show the main form  Form1.Visible := True;  //Clear up time  ReleaseDc(GetDesktopWindow, dc);  img.Free;end;`

#### BlueIcaro

• Hero Member
• Posts: 595
« Reply #1 on: July 17, 2011, 05:30:29 pm »
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

#### typo

• Hero Member
• Posts: 3051
« Reply #2 on: July 17, 2011, 05:49:09 pm »
Replace this:

Code: [Select]
`BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height, dc, 0, 0, SRCCOPY);`
by this:

Code: [Select]
`img.Picture.Bitmap.LoadFromDevice(dc);`

• Full Member
• Posts: 121