🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problem with Thread and OnPaint

#17130
From: Phuoc Can HUA
Date: Mon, 07 Apr 2003 05:08
36 lines
2669 bytes
"Remy Lebeau (TeamB)" <gambit47@yahoo.com> wrote in message
news:3e90fe9b$1@newsgroups.borland.com...
> It is hard to diagnose your problem without seeing yuor actual code.  But
> offhand, it sounds like you are trying to draw directly onto the PaintBox
> from your thread directly.  If so, then you shouldn't be doing that, as
the
Yes, the thread is drawing using several Canvas and copy the results from
the WorkSpace to PaintBox and this is running all the time. I had some
problems with Canvas before, until I use Lock/Unlock. I also tried to use
lock on PaintBox. But somehow the whole OnPaint routine stuck :-)

> VCL is not thread-safe and can't handle cross-thread painting correctly.
> Instead, you should be doing your thread-based drawing to a separate
> in-memory bitmap that is properly protected by a synchronization object
> (mutex, critical section, semaphore, etc), and then the thread can obtain
> the lock to the bitmap when it needs to alter the bitmap, and then the
> OnPaint event can obtain the lock when it needs to update the PaintBox
with
> the bitmap.  That way, only one is trying to access the bitmap at any
given
> time.
Haven't got all what you mean. Do you mean... the thread only draws on a
bitmap (Canvas?) without copying the results to the PaintBox. But how can I
display the results? Do I have to trigger OnPaint to refresh the image? Will
the OnPaint re-paint the entire image?

Currently, my OnPaint seems to be running 'wild'. As I mentioned, sometimes
it just draws on the screen across several windows.

Phuoc Can HUA


--
_/\__/\__/\__/\__/\__/\_
www.huaonline.com
My Homepage is my Castle
Technical Details
Message-ID: <3e9107d2$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e90c1f3$1@newsgroups.borland.com> <3e90fe9b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,f582f476470f4983
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-06 22:12:44 PST
From: "Phuoc Can HUA" <home+a+t+huaonline.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e90c1f3$1@newsgroups.borland.com> <3e90fe9b$1@newsgroups.borland.com>
Subject: Re: Problem with Thread and OnPaint
Date: Mon, 7 Apr 2003 15:08:48 +1000
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 210.9.89.210
Message-ID: <3e9107d2$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1049692114 210.9.89.210 (6 Apr 2003 22:08:34 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail