Article View: borland.public.cppbuilder.nativeapi
Article #14922Re: What is wrong with this code
From: Clayton Arends
Date: Sun, 27 Jul 2003 16:37
Date: Sun, 27 Jul 2003 16:37
43 lines
2266 bytes
2266 bytes
"micheal davis" <micheal_davis@hotmail.com> wrote in message
news:3f23d46d@newsgroups.borland.com...
> I am getting access violation every time I try to execute the following
> code ...
TJPEGImage cannot load the clipboard format for a bitmap. Try the following
code instead. I've converted your code to use std::auto_ptr to delete the
temporary objects instead of try..finally since it is better for a C++
program to use this facility. Also, the line where you deleted 'CBContent'
was a no-no. You do not own this object.
#include <memory>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TClipboard *CBContent = Clipboard();
keybd_event(VK_SNAPSHOT, 0, 0, 0);
if (SaveDialog1->Execute())
{
TJPEGImage* jp = new TJPEGImage;
std::auto_ptr<TJPEGImage> auto_jp(jp);
if (CBContent->HasFormat(CF_BITMAP))
{
Graphics::TBitmap* bm = new Graphics::TBitmap;
std::auto_ptr<Graphics::TBitmap> auto_bm(bm);
bm->LoadFromClipboardFormat(CF_BITMAP,
CBContent->GetAsHandle(CF_BITMAP), 0);
jp->Assign(bm);
}
// add else conditions for different formats, if necessary
jp->Compress();
jp->SaveToFile(SaveDialog1->FileName);
}
}
HTH,
- Clayton
Technical Details
Message-ID:
<3f23ffa5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f23d46d@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,3d8447d7c3e5ad9d X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-07-27 09:39:30 PST From: "Clayton Arends" <nospam_claytonarends@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f23d46d@newsgroups.borland.com> Subject: Re: What is wrong with this code Date: Sun, 27 Jul 2003 09:37:09 -0700 Lines: 45 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: 24.30.128.202 Message-ID: <3f23ffa5$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1059323813 24.30.128.202 (27 Jul 2003 09:36:53 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail