Clearing DrawText before next Draw...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Clearing DrawText before next Draw...

  1. #1
    Join Date
    May 2009
    Posts
    103

    Clearing DrawText before next Draw...

    This might be a rudimentary issue... but I have no clue as how to do this.

    Have an application that had a series of DrawText calls in a CDC and CRect. Works well. Client wants me to add a "clock" under the text. Took what they had, added the GetLocalTime call to get the time and used a copy of the previous DrawText steps to add it to the display.

    Worked.... except....

    As the seconds tick away, it OVERWRITES the existing DrawText and "stacks" them one on top of the other. Was going to SetBackMode to OPAQUE but they need to have the background color(s) show through (it's multicolor).

    Thought about old school and just writing a bunch of spaces before laying the next DrawText.... that didn't work.

    I am sure this is pretty basic... but for the life of me, I am not sure which way to go and am getting tired of trial an errors (or should I say errors and errors).

    Suggestions from the helpful people at CodeGuru?

    Thanks.... snippet of code follows

    Code:
    CDC dc;
    HDC hDC = GetDC(hWnd);
    dc.Attach(hDC);
    CRect rect
    SYSTEMTIME sysTime;
    
    ...
    
    
    dc.SetBkMode(TRANSPARENT);
    dc.SetTextColor(RGB(255, 255, 255));
    
    CString sTemp = "Line Number 1";
    font.CreateFont(rect.Height() / 10, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, "Arial");
    oldFont = dc.SelectObject(&font);
    int iTextHeight = dc.DrawText(sTemp, &rect, DT_CENTER);
    dc.SelectObject(oldFont);
    font.DeleteObject();
    rect.OffsetRect(0, iTextHeight);
    
    sTemp = "Line Number 2";
    font.CreateFont(rect.Height() / 18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, "Arial");
    oldFont = dc.SelectObject(&font);
    int iTextHeight = dc.DrawText(sTemp, &rect, DT_CENTER);
    dc.DrawText(sTemp, &rect, DT_CENTER);
    dc.SelectObject(oldFont);
    font.DeleteObject();
    rect.OffsetRect(0, iTextHeight);
    
    GetLocalTime(&sysTime);
    sTemp.Format("%.2u:%.2u:%.2u", sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
    font.CreateFont(rect.Height() / 12, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, "Arial");
    oldFont = dc.SelectObject(&font);
    dc.DrawText(sTemp, &rect, DT_CENTER);
    dc.SelectObject(oldFont);
    font.DeleteObject();

  2. #2
    Join Date
    Dec 2004
    Location
    Ann Arbor, MI
    Posts
    281

    Re: Clearing DrawText before next Draw...

    Can you give us more info about what type of window and where this is called from? Dialog, View, OnPaint(), what?

    My first inclination is to say that you need an InvalidateRect() call somewhere.
    --EJMW

  3. #3
    Join Date
    May 2009
    Posts
    103

    Re: Clearing DrawText before next Draw...

    I can try... I'm just modifying a previous programmers code..... so....

    The "window" is the entire screen. This is actually a screen saver and the writing is centered on the screen. I am beginning to NOT like ScreenSaver coding... touch to debug and test (& understand)!!!

    The rect looks like it is created with...

    Code:
    GetWindowRect(hWnd, &rect);
    
    int iWidth = rect.Width() / 3;
    int iHeight = rect.Height() / 3;
    int iBox=0;
    
    rect.SetRect(iWidth * (iBox % 3), iHeight * ((int)(iBox / 3)), iWidth * (iBox % 3) + iHeight, iHeight * (((int)(iBox / 3))) + iHeight);
    rect.OffsetRect((iWidth - iHeight) / 2, 0);
    Hope this helps....

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center