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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make an array of Brushes?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want to create an array of brushes (a &quot;palette&quot;) and the following syntax:<br><br><FONT FACE=monospace>CBrush brushes[] =<br>{<br>CBrush(RGB(255,0,0)),<br>CBrush(RGB(0,255,0)),<br>CBrush(RGB(0,0,255))<br>}</font><br><br>is incorrect because no copy constructor is available for this class.<br>Tell me, what should I do?<br>
 
Yes that is by design since you don't want to hold on to GDI resources outside of 'paint' code.<br><br>So your palett should be an array of COLORREF like this:<br><br>COLORREF Palette[] = {<br>RGB(255,0,0),<br>RGB(0,255,0),<br>RGB(0,0,255)<br>};<br><br>Then you create the brushes at paint time from the palette values and free them up before exiting the painting code.<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete<br><br>
 
Thanks...<br>So tell me if I get it:<br><br>I write your code:<br><br><FONT FACE=monospace>COLORREF Palette[] = {<br>RGB(255,0,0),<br>RGB(0,255,0),<br>RGB(0,0,255)<br>};<br></font><br>Then in OnPaint() for example, I create a brush:<br><br><FONT FACE=monospace>CBrush brush = new CBrush(Palette[2]);</font><br><br>At the end of the function I should add:<br><br><FONT FACE=monospace>delete brush;</font><br><br>Is it right to do it this way or may I do this:<br><FONT FACE=monospace>CBrush brush(Palette[2]);</font><br><br>...and use it directly (without deleting it)?
 
The MFC documentation suggests using the stack frame:<br><br>CBrush brush(Palette[2]);<br><br>Good luck<br>-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top