🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16558

Re: Capture screen

#16558
From: Remy Lebeau (TeamB)
Date: Wed, 07 May 2003 06:57
68 lines
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
Technical Details
Message-ID: <3eb8adfe$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3eb8a7f7@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,a7ce8a0d5db2cfe5
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-05-07 00:07:19 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3eb8a7f7@newsgroups.borland.com>
Subject: Re: Capture screen
Date: Tue, 6 May 2003 23:57:44 -0700
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3eb8adfe$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1052290558 207.175.226.26 (6 May 2003 23:55:58 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail