Click to See Complete Forum and Search --> : CDC confusion...


Jaime Wyant
April 20th, 1999, 09:45 AM
I have some classes that are as follows:

CTreeCtrl
|
|
MyTree1
|
|
MyTree2

In 'MyTree2', there are instances where the tree will be empty, and I want to display some text in the window instead. I tried grabbing a DC and doing a .TextOut(), but this does not work... Unless I use a CPaintDC. But, I read that I should only use a CPaintDC in response to a OnPaint() [ WM_PAINT msg ]...

Below are my code snippets:

// This one don't work
CClientDC dc(this);
dc.TextOut(0, 0, "No employee selected for this view");

// This does work...
CPaintDC* pDC = new CPaintDC(this);
pDC->TextOut(10,50, "No employee selected for this view");
delete pDC;

Can anyone give me a clue?

Thanks,
Jaime

April 20th, 1999, 01:00 PM
the first does not work because the OnPaint for the tree control probably overwrites the text you output. The second one does work because the CPaintDC will validate the painting rectangle for you, thus the tree control does not receive it's normal OnPaint because there is not an invalidated region to be painted any more. I have found that the advice to use CPaintDC only in an OnPaint is given because you may validate an area by mistake that really does need to get painted