🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
8 messages
8 total messages Started by Jeff Thu, 21 Jun 2007 16:23
Clipboard operation w/ Icons
#1711
Author: Jeff
Date: Thu, 21 Jun 2007 16:23
18 lines
1723 bytes
I've got a TImage component (imgMonitor below) that is displaying an icon 
via ExtractIcon().  The problem is that the Windows clipboard doesn't 
support icons.  I've tried creating a TBitmap and coping it and assigning it 
to the clipboard (see code below), but programs throw errors when attempting 
to paste.  Any ideas on how to get this to work?

    Graphics::TBitmap *tBitmap = new Graphics::TBitmap;

    tBitmap->Width = imgMonitor->Picture->Bitmap->Width;
    tBitmap->Height = imgMonitor->Picture->Bitmap->Height;
    tBitmap->PixelFormat = imgMonitor->Picture->Bitmap->PixelFormat;
    tBitmap->Canvas->Draw(0,0,imgMonitor->Picture->Icon);
    imgMonitor->Picture->Graphic = tBitmap;
    Clipboard()->Assign(imgMonitor->Picture);
    delete tBitmap;

Thanks,
Jeff 
Re: Clipboard operation w/ Icons
#1713
Author: Bob Gonder
Date: Thu, 21 Jun 2007 17:02
9 lines
1157 bytes
Jeff wrote:

>    imgMonitor->Picture->Graphic = tBitmap;
>    Clipboard()->Assign(imgMonitor->Picture);

I would say either
    Clipboard()->Assign( imgMonitor->Picture-Graphic );
or
    Clipboard()->Assign( tBitmap );
Re: Clipboard operation w/ Icons
#1714
Author: Jeff
Date: Thu, 21 Jun 2007 17:05
8 lines
1195 bytes
> I would say either
>    Clipboard()->Assign( imgMonitor->Picture-Graphic );
> or
>    Clipboard()->Assign( tBitmap );

I've tried both methods and still receive an error when pasting.

Thanks. 
Re: Clipboard operation w/ Icons
#1715
Author: 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
Re: Clipboard operation w/ Icons
#1716
Author: Remy Lebeau (TeamB)
Date: Thu, 21 Jun 2007 17:23
13 lines
1254 bytes
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message
news:cmbl73l030v30mkcmtrbqccjcofs1flmsc@4ax.com...

>     Clipboard()->Assign( imgMonitor->Picture-Graphic );

That will not work if the Picture contains a TIcon.  When passing a
TGraphic to TClipboard::Assign(), it calls the
TGraphic::SaveToClipboardFormat() method, which TIcon does not
implement.


Gambit
Re: Clipboard operation w/ Icons
#1718
Author: Jeff
Date: Thu, 21 Jun 2007 18:41
1 lines
953 bytes
Thank you very much, as you can tell from my code I was a little confused. 
Re: Clipboard operation w/ Icons
#1723
Author: Bob Gonder
Date: Fri, 22 Jun 2007 16:56
11 lines
1465 bytes
Remy Lebeau (TeamB) wrote:
>"Bob Gonder"  wrote in message
>
>>     Clipboard()->Assign( imgMonitor->Picture-Graphic );
>
>That will not work if the Picture contains a TIcon.

I thought it contained a TBitmap.

>    Graphics::TBitmap *tBitmap = new Graphics::TBitmap;
>    imgMonitor->Picture->Graphic = tBitmap;
Re: Clipboard operation w/ Icons
#1726
Author: Remy Lebeau (TeamB)
Date: Fri, 22 Jun 2007 17:44
20 lines
1651 bytes
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message
news:hlvn73df61gagpvhrug27sc7plob3ka94o@4ax.com...

> I thought it contained a TBitmap.

The OP said:

    "I've got a TImage component (imgMonitor below) that is displaying
an icon via ExtractIcon()."

His original code was completely wrong, as I already pointed out to
him.  There was no need to try to convert the TImage over to a TBitmap
inside the TImage.  He can preserve the original TIcon as-is and still
copy a temporary TBitmap to the clipboard.  If he corrects his code to
do that, then calling Clipboard()->Assign() while the TImage still
holds a TIcon will not work, but it doesn't need to anyway.


Gambit
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