Article View: borland.public.cppbuilder.nativeapi
Article #17675Re: OnPaint with Semaphore seems not working...
From: Oliver Rutsch
Date: Wed, 05 Mar 2003 08:28
Date: Wed, 05 Mar 2003 08:28
108 lines
5034 bytes
5034 bytes
Hi Phuoc,
[...]
> all. The funny thing is if I leave my program running without any movement
> the graphic is fine. Luckily, I found someone has experienced the same thing
> :-)
Yes, unfortunately that is exactly what I found.
>
> I used to use WinAPI to draw. But then I thought that's the time of Win3.x
> and it's no long up-to-date :-) So, I tried the BCB lib.
> Can you give me any advice to convert my CopyRect to WinAPI? Is there a
> similar function and with binary operation (CopyMode)?
O.K. Here's some example code from one of my components. It is derived
from TCustomControl and does nothing else but painting some rotating
gears out of a resource. Paint() is called from the thread because I
want that it looks smooth, even if the main thread has some work to do.
Looks cool ;-) Do you have access to the MSDN? There is a lot of
information to all the commands I used. Too much to mention here ;-)
void __fastcall TWxGears::Paint()
{
// Don't do anything if your component is not visible
if (!Visible)
return;
// Stop drawing if the component gets destroyed
if (ComponentState.Contains(csDestroying))
return;
// PaintLock is a TCriticalSection, Lock the section
PaintLock->Acquire();
HDC MyDC;
HDC hdcCompatible;
DWORD Index;
String ResName;
HBITMAP MyBitmap;
try
{
// Get the device context of the components window handle
// Don't cache this, because the handle to the DC can only
// be used by a single thread at any one time.
MyDC=GetDC(Handle);
// throws are just for testing purpose
if (!MyDC)
throw 0;
// Load a bitmap out of a resource
Index=PicCounter%NumBitmaps;
ResName="GEAR"+String(Index+1)+"_"+String(EnumToSize(Size));
MyBitmap=LoadBitmap((void*)HInstance,ResName.c_str());
if (!MyBitmap)
throw 1;
// Create a memory device context
hdcCompatible = CreateCompatibleDC(MyDC);
if (!hdcCompatible)
throw 2;
// ...and select the bitmap into the dc
if (!SelectObject(hdcCompatible, MyBitmap))
throw 3;
DWORD Offset=FRaised ? 3 : 0;
// Gr��e ge�ndert ?
ClientHeight=EnumToSize(Size)+Offset*2;
ClientWidth=EnumToSize(Size)+Offset*2;
// blit the bitmap into the components surface
// have a look at the last parameter, it defines the
// copy mode
if (!BitBlt(MyDC,Offset,Offset,ClientWidth,ClientHeight,
hdcCompatible,0,0,SRCCOPY))
throw 4;
if (FRaised)
{
RECT MyRect;
MyRect.left=0;
MyRect.top=0;
MyRect.right=ClientWidth;
MyRect.bottom=ClientHeight;
// Draw a nice border if raised
if (!DrawEdge(MyDC,&MyRect,EDGE_RAISED,BF_RECT))
throw 5;
}
}
catch(...){}
// free resources
ReleaseDC(Handle,MyDC);
DeleteDC(hdcCompatible);
DeleteObject(MyBitmap);
PaintLock->Release();
}
> Since I also plan to compile my program with Kylix for Linux (maybe one day)
> :-) shouldn't I avoid to use too many WinAPI's, what do you think?
> Should I have a look in SDL (www.libsdl.org)? Will I have the same problem
> with SDL?
>
If you plan multiplatform developing then I would avoid multithreaded
visual components. For multithreading I would look at some multiplatform
frameworks like ACE (has some very nice multithreading classes, but it
is NOT a GUI framework!) and avoid pure Win32 API.
Hmm, as far as I know SDL is for developing games and not a
GUI-Framework like the VCL. I don't know more about this library, sorry.
Bye,
--
Dipl. Ing. Oliver Rutsch
EMail: orutsch at sympatec.com
Sympatec GmbH Germany
Technical Details
Message-ID:
<1046852893.659323@post.sympatec.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3e63f403$1@newsgroups.borland.com> <1046770772.980524@post.sympatec.net> <3e652410$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10cc67,7b93bd55840acb0 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-03-05 01:00:05 PST Date: Wed, 05 Mar 2003 09:28:13 +0100 From: Oliver Rutsch <nospam@sympatec.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: de, en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: OnPaint with Semaphore seems not working... References: <3e63f403$1@newsgroups.borland.com> <1046770772.980524@post.sympatec.net> <3e652410$1@newsgroups.borland.com> In-Reply-To: <3e652410$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Organization: Ye 'Ol Disorganized NNTPCache groupie Message-ID: <1046852893.659323@post.sympatec.net> Cache-Post-Path: post.sympatec.net!unknown@rutsch2.tksympatec X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 217.6.163.138 X-Trace: newsgroups.borland.com 1046852892 217.6.163.138 (5 Mar 2003 00:28:12 -0800) Lines: 109 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail