Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

CPaintDC context outside OnPaint()

$
0
0

So I have the following code to draw somewhat of a ">" in my OnPaint() function:

void CChildView::OnPaint()
{
CPaintDC pDC(this); // device context for painting
...
int i1, i2;
i1 = RightSide -50;
i2 = (Bottom - Top)/2-31;
for (int ii=0; ii<31; ii++)
	{
	pDC.PatBlt(i1++ ,i2++ , 8, 1, DSTINVERT);
	}
for (int ii=0; ii<31; ii++)
	{
	pDC.PatBlt(i1--,i2++ , 8, 1, DSTINVERT);
	}
...

So, I am going to use this code repeatedly, like later to erase the ">", so I create a function:

void CChildView::RArrowOn(void) { CPaintDC pDC2(this); // device context for painting int i1, i2; i1 = Right-50; i2 = (Bottom - Top)/2-31; for (int ii=0; ii<31; ii++) { pDC2.PatBlt(i1++ ,i2++ , 8, 1, DSTINVERT); } for (int ii=0; ii<31; ii++) { pDC2.PatBlt(i1--,i2++ , 8, 1, DSTINVERT); } }

So, those of you who are good at this know (as I have found out by reading lots of "help" files), you can't use a CPaintDC outside of OnPaint(). So I tried passing passing pDC to the function, which also didn't work as I suspected (but I tried anyway).

I really don't want to duplicate this code and a lot of similar code in various places in OnPaint(). A solution would be appreciated, and I have a feeling there is a simple solution.


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>