tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Newcomer to TCC (and C) with a couple of questions..


From: Kalle Olavi Niemitalo
Subject: Re: [Tinycc-devel] Newcomer to TCC (and C) with a couple of questions..
Date: Thu, 02 Apr 2009 11:17:19 +0300
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.51 (gnu/linux)

lostgallifreyan <address@hidden> writes:

> Do the required deletions of device contexts (to spare GDI
> resources) get done by code compiled by TCC, or do I have to do
> this explicitly, as I do in wxLua, for example?

AFAIK, TCC does not have any specific support for Windows GDI
and does not automatically generate code to delete GDI objects.
So if Windows requires your program to delete some GDI objects,
then you must yourself write the appropriate GDI calls.

> I ask because in wxLua, every colour, every pen and brush, is a
> DC that must be deleted the instant no longer required, yet the
> single GUI example supplied with TCC has a colour (COLORREF)
> for text colour that does not appear to have a specific
> deletion following it.

I don't think Windows GDI requires programs to delete COLORREFs.
Generally, if you allocate a resource with some Windows function,
then the documentation of that function says how you should free
that resource.  If you construct a COLORREF with the RGB macro
<http://msdn.microsoft.com/en-us/library/dd162937(VS.85).aspx>
then this documentation does not say you need to free the
returned COLORREF.  Likewise with the GetSysColor function
<http://msdn.microsoft.com/en-us/library/ms724371(vs.85).aspx>.
And the documentation of COLORREF itself
<http://msdn.microsoft.com/en-us/library/dd183449(VS.85).aspx>
says the COLORREF value just contains the RGB component values
in its individual bytes.  Thus, no actual resource has been
allocated in Windows and there is nothing to free.  (With
"resource" here, I don't mean the things you compile with
Resource Compiler and link into *.exe files.)

If you create a brush (HBRUSH) with CreateSolidBrush
<http://msdn.microsoft.com/en-us/library/dd183518(VS.85).aspx>
then the documentation says you need to delete it with
DeleteObject.  But if you instead use GetSysColorBrush
<http://msdn.microsoft.com/en-us/library/dd144927(VS.85).aspx>
then you must not delete the brush.  So always read the
documentation.

Note also that Windows GDI provides ways of drawing different
colours while using just one device context and one pen or brush:
e.g. GetStockObject(DC_BRUSH) with SetDCBrushColor.  That may be
faster than creating a separate pen or brush for each colour.
You mention Windows 98 though; I don't know whether this works
there, as Microsoft has ended support for that OS and removed
from the MSDN library apparently all information on which
functions are compatible with that.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]