Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by FrankW
Wed, 07 May 2003 06:30
Capture screen
Author: FrankW
Date: Wed, 07 May 2003 06:30
Date: Wed, 07 May 2003 06:30
75 lines
2635 bytes
2635 bytes
Hi,
Can anybody offer tips on how to capture a screen image? I came across a
Delphi code 'ScreenShot', but have problem converting it to C++, anybody can
help?
Thanks,
procedure ScreenShot(hWindow: HWND; bm: TBitmap);
var
Left, Top, Width, Height: Word;
R: TRect;
dc: HDC;
lpPal: PLOGPALETTE;
begin
{Check if valid window handle}
if not IsWindow(hWindow) then Exit;
{Retrieves the rectangular coordinates of the specified window}
GetWindowRect(hWindow, R);
Left := R.Left;
Top := R.Top;
Width := R.Right - R.Left;
Height := R.Bottom - R.Top;
bm.Width := Width;
bm.Height := Height;
{get the screen dc}
dc := GetDc(0);
if (dc = 0) then
begin
Exit;
end;
{do we have a palette device?}
if (GetDeviceCaps(dc, RASTERCAPS) and
RC_PALETTE = RC_PALETTE) then
begin
{allocate memory for a logical palette}
GetMem(lpPal,
SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)));
{zero it out to be neat}
FillChar(lpPal^,
SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)),
#0);
{fill in the palette version}
lpPal^.palVersion := $300;
{grab the system palette entries}
lpPal^.palNumEntries :=
GetSystemPaletteEntries(dc,
0,
256,
lpPal^.palPalEntry);
if (lpPal^.PalNumEntries <> 0) then
begin
{create the palette}
bm.Palette := CreatePalette(lpPal^);
end;
FreeMem(lpPal, SizeOf(TLOGPALETTE) +
(255 * SizeOf(TPALETTEENTRY)));
end;
{copy from the screen to the bitmap}
BitBlt(bm.Canvas.Handle,
0,
0,
Width,
Height,
Dc,
Left,
Top,
SRCCOPY);
{release the screen dc}
ReleaseDc(0, dc);
end;
Re: Capture screen
Author: Remy Lebeau (TeamB)
Date: Wed, 07 May 2003 06:57
Date: Wed, 07 May 2003 06:57
68 lines
2820 bytes
2820 bytes
"FrankW" <nospam@nospam.com> wrote in message
news:3eb8a7f7@newsgroups.borland.com...
> I came across a Delphi code 'ScreenShot', but have
> problem converting it to C++
It would help if you would specify the actual problems you are having with
it.
Here is a translation for you:
void __fastcall ScreenShot(HWND hWindow, Graphics:::TBitmap *bm)
{
LONG Left, Top, Width, Height;
RECT R;
HDC dc;
PLOGPALETTE lpPal;
// Check if valid window handle
if( !IsWindow(hWindow) ) return;
// Retrieves the rectangular coordinates of the specified window
GetWindowRect(hWindow, &R);
Left = R.left;
Top = R.top;
Width = (R.right - R.left);
Height = (R.bottom - R.top);
bm->Width = Width;
bm->Height = Height;
// get the screen dc
dc = GetDC(0);
if( dc == NULL ) return;
// do we have a palette device?
if( (::GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE) == RC_PALETTE )
{
// allocate memory for a logical palette
lpPal = (PLOGPALETTE) ::GlobalAlloc(GPTR, sizeof(LOGPALETTE) +
(255 * sizeof(PALETTEENTRY)));
// fill in the palette version
lpPal->palVersion = 0x300;
// grab the system palette entries
lpPal->palNumEntries = ::GetSystemPaletteEntries(dc, 0, 256,
lpPal->palPalEntry);
if( lpPal->palNumEntries != 0 )
{
// create the palette
bm->Palette = ::CreatePalette(lpPal);
}
::GlobalFree((HGLOBAL)lpPal);
}
// copy from the screen to the bitmap
::BitBlt(bm->Canvas->Handle, 0, 0, Width, Height, dc, Left, Top,
SRCCOPY);
// release the screen dc
ReleaseDC(0, dc);
}
Gambit
Re: Capture screen
Author: FrankW
Date: Wed, 07 May 2003 15:31
Date: Wed, 07 May 2003 15:31
19 lines
1471 bytes
1471 bytes
Hi, Thanks for the excellent translation, it works ! Frank "Remy Lebeau (TeamB)" <gambit47@yahoo.com> wrote in message news:3eb8adfe$1@newsgroups.borland.com... > > "FrankW" <nospam@nospam.com> wrote in message > news:3eb8a7f7@newsgroups.borland.com... > > > I came across a Delphi code 'ScreenShot', but have > > problem converting it to C++ > > It would help if you would specify the actual problems you are having with > it. > > Here is a translation for you:
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads