🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Clipboard operation w/ Icons

#1715
From: Remy Lebeau (TeamB)
Date: Thu, 21 Jun 2007 17:22
54 lines
3027 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:467aa666$1@newsgroups.borland.com...

> programs throw errors when attempting to paste.

That is likely because you are completely wiping out your Icon before
you can copy it to the clipboard.  You are accessing the TPicture's
Bitmap property when querying the image information.  If the TPicture
does not contain a TBitmap (which it does not in your case), the
current Graphic (the icon) is destroyed and replaced with an empty
TBitmap.  You are then using the Icon property to draw the image onto
your temporary TBitmap.  Accessing the Icon property is going to
destroy that empty TBitmap and replace it with an empty TIcon.  If you
read the documentation for TPicture, this is clearly explained:

    TPicture::Bitmap
    "If Bitmap is referenced when the picture contains a Metafile or
Icon graphic, the graphic won't be converted. Instead, the original
contents of the picture are discarded and Bitmap returns a new, blank
bitmap."

    TPicture::Icon
    "If Icon is referenced when the TPicture contains a Bitmap or
Metafile graphic, the graphic won't be converted. Instead, the
original contents of the TPicture are discarded and Icon returns a
new, blank icon."

Worse, you are then assigning your temporary TBitmap back to the
TImage.  Since the TBitmap is sized to 0,0 with no valid drawing in
it, you are then wiping out the TPicture again and replace its
contents with another empty TBitmap.

To preserve the original icon, you need to change your code to the
following instead:

    Graphics::TBitmap *tBitmap = new Graphics::TBitmap;
    tBitmap->Width = imgMonitor->Picture->Icon->Width;
    tBitmap->Height = imgMonitor->Picture->Icon->Height;
    tBitmap->Canvas->Draw(0, 0, imgMonitor->Picture->Icon);
    Clipboard()->Assign(tBitmap);
    delete tBitmap;

Or, more generically:

    Graphics::TBitmap *tBitmap = new Graphics::TBitmap;
    tBitmap->Width = imgMonitor->Picture->Graphic->Width;
    tBitmap->Height = imgMonitor->Picture->Graphic->Height;
    tBitmap->Canvas->Draw(0, 0, imgMonitor->Picture->Graphic);
    Clipboard()->Assign(tBitmap);
    delete tBitmap;


Gambit
Technical Details
Message-ID: <467ab409$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <467aa666$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,94c464a24f7a5b5e
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <467aa666$1@newsgroups.borland.com>
Subject: Re: Clipboard operation w/ Icons
Date: Thu, 21 Jun 2007 10:22:25 -0700
Lines: 56
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.82.252.126
Message-ID: <467ab409$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1182446601 75.82.252.126 (21 Jun 2007 10:23:21 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail