Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer, Printscreen, and TBitmap::SaveToFile

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
Hallo - I have somw code that looks like this:

void __fastcall Tmainform::tmrClickTimer(TObject *Sender)
{
if(!doing){
doing=true;
char buffer[16];
int len;
keybd_event(VK_SNAPSHOT,0,0,0);
if(clp->HasFormat(CF_BITMAP))
bmp->LoadFromClipboardFormat(CF_BITMAP,clp->GetAsHandle(CF_BITMAP),0);
string fname="C:\\temp\\stream_pics\\ss";
ltoa(num,buffer,10);
len=8-strlen(buffer);
for(int i=0;i<len;i++)
fname+=&quot;0&quot;;
fname+=buffer;
fname+=&quot;.bmp&quot;;
bmp->SaveToFile(fname.c_str());
num++;
doing=false;
}
}

As that looks like a total pig, I'll exlpain - I have a Clipboard, a Bitmap, a Timer and a number. Each time the timer's event is called, I call PreintScreen with a keybd_event, then copy from the clipboard to the bitmap. I then want to save that to file. There is a bool called 'doing' that's supposed to save me from screw ups, but it doesn't seem to.

Can anybody suggest why this is failing (always on the line where the string fname is declared)? I guess it's because of multiple calls to the timer. If so, anyone any ideas?

Cheers,
Douglas JL

If it don't make you laugh, it ain't true.
 
I'm sure you already have, but have you stepped through the code in debug to make sure it is not failing on

bmp->LoadFromClipboardFormat(CF_BITMAP,clp->GetAsHandle(CF_BITMAP),0);
 
Yeah - it was definately the string 'fname' it was failing on. Common sense is what tells you the world is flat.
 
So was it just the "fname" string that was the problem? I'm getting a very similar problem with doing a SaveToFile from inside an OnTimer function.... I keep getting messages about out of resourses and other non-sensical Borland exception top tips.

Any help would be good, because I've been stuck on this for the best part of a day and a half now!

Cheers.
 
you guys are the experts, so I guess Ill state
the obvious. the line that the code "Fails on"
can be the line after the problematic code. I look
at the code before the problem occurs.

on the line wings pointed to

bmp->LoadFromClipboardFormat(CF_BITMAP,clp->GetAsHandle(CF_BITMAP),0);

declare your string earlier and see if the fault moves with the declaration.
 
Yeah... Some bugs take longer to fix than others. I admit three years a bit a long one.

Seems its a fault in Borland Debugger... The problem doesn't happen if I run the Debug or Release EXE standalone.

Thanks Borland. That VC re-write gets closer every day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top