Board index » cppbuilder » Copy a control to clipboard as a bitmap ??

Copy a control to clipboard as a bitmap ??

Hi!

Have searched the help files and exemples but have not found any 100%
solution.

I have reached so far: (here is my code)
//---------------------------------------------------------------
TClipboard     *cb = new TClipboard();
   Graphics::TBitmap   *image = new Graphics::TBitmap();

    //rgErrDitr is a radioGroup control:
   image->Width = rgErrDistr->Width;
   image->Height = rgErrDistr->Height;

   rgErrDistr->PaintTo( image->Canvas, 0, 0);
   cb->Open();
   cb->Assign( image);
   cb->Close();
   delete cb;
//---------------------------------------------------------------
When I paste from clipboard into e.g. Paint, I get a white bitmap, of
the right size, but no nothing else...

Any help ???

Regards
Per K?re  Foss
Geologica

 

Re:Copy a control to clipboard as a bitmap ??


You need to get that portion of the form's canvas and copy that to the
bitmap and the radiogroup control will be visible. BTW use copyrect.
-jc

Quote
Per K?re Foss wrote:
> Hi!

> Have searched the help files and exemples but have not found any 100%
> solution.

> I have reached so far: (here is my code)
> //---------------------------------------------------------------
> TClipboard     *cb = new TClipboard();
>    Graphics::TBitmap   *image = new Graphics::TBitmap();

>     //rgErrDitr is a radioGroup control:
>    image->Width = rgErrDistr->Width;
>    image->Height = rgErrDistr->Height;

>    rgErrDistr->PaintTo( image->Canvas, 0, 0);
>    cb->Open();
>    cb->Assign( image);
>    cb->Close();
>    delete cb;
> //---------------------------------------------------------------
> When I paste from clipboard into e.g. Paint, I get a white bitmap, of
> the right size, but no nothing else...

> Any help ???

> Regards
> Per K?re  Foss
> Geologica

Re:Copy a control to clipboard as a bitmap ??


Hi,

I've used the following to copy an image of an entire form to the
clipboard:

//... in button-click handler for form
    Graphics::TBitmap *Bmp = new Graphics::TBitmap;
    Bmp->Width = Width;
    Bmp->Height = Height;

    HDC aDC =  GetWindowDC(Handle);
/// replace Handle above with YourControl->Handle

    ::BitBlt(Bmp->Canvas->Handle, 0,0, Width, Height,
            aDC, 0,0, SRCCOPY);
    ReleaseDC(Handle, aDC);
/// replace Handle above with YourControl->Handle

    Clipboard()->Assign(Bmp);

    delete Bmp;
//.. end snip

It appears that you cant directly get to the Canvas (=DC) of a TControl,
but your could BCB'ify (or de-API'fy) the example above by using
YourControl->GetDeviceContext() and assigning that to the Handle of a
newly created TCanvas - but why bother...

regards

Per Laursen

Quote
Per K?re Foss wrote:

> Hi!

> Have searched the help files and exemples but have not found any 100%
> solution.

> I have reached so far: (here is my code)
> //---------------------------------------------------------------
> TClipboard     *cb = new TClipboard();
>    Graphics::TBitmap   *image = new Graphics::TBitmap();

>     //rgErrDitr is a radioGroup control:
>    image->Width = rgErrDistr->Width;
>    image->Height = rgErrDistr->Height;

>    rgErrDistr->PaintTo( image->Canvas, 0, 0);
>    cb->Open();
>    cb->Assign( image);
>    cb->Close();
>    delete cb;
> //---------------------------------------------------------------
> When I paste from clipboard into e.g. Paint, I get a white bitmap, of
> the right size, but no nothing else...

> Any help ???

> Regards
> Per K?re  Foss
> Geologica

Other Threads