CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    14

    CDC confusion...

    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



  2. #2
    Guest

    Re: CDC confusion...

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured