Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DrawText() blinking problem

DrawText() blinking problem

Scheduled Pinned Locked Moved C / C++ / MFC
adobehelp
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    I met a weird DrawText() blinking problem. in a loop, interval is 2 seconds, I want to show some messages on a dialog screen. i.e. 0-2 sec, message1; 2-4 sec,message2; 4-6, message3 ... but, now the message shows like: flash message1; 0 sec black screen; flash message2; 2 sec black screen; flash message3; 6 sec. black screen; what I want is : message1; 0-2 sec message2; 2-4 sec message3; 4-6 sec

    void CTestDlg::DrawMsg(LPCTSTR iMsgStr)
    {
    CDC* pDC;
    CRect rect;
    CString MsgStr;
    HDC hDC;
    LOGFONT lf;
    HFONT FontNew, FontOld;

    pDC = GetDC();
    hDC = pDC->GetSafeHdc();

    memset(&lf, 0, sizeof(LOGFONT));
    lf.lfHeight = -14 * GetDeviceCaps(hDC,LOGPIXELSY)/72;
    lf.lfWeight = 0;
    FontNew = CreateFontIndirect(&lf);
    FontOld = (HFONT)SelectObject(hDC,FontNew);

    rect.SetRect(CPoint(274,442), CPoint(514,514));
    SetBkMode(hDC,TRANSPARENT);

    DrawText(hDC,dtcMsgStr,-1,rect,DT_WORDBREAK|DT_LEFT);
    InvalidateRect(rect,FALSE);

    SelectObject(hDC,FontOld);
    DeleteObject(FontNew);
    ReleaseDC(pDC);
    }

    PJ ArendsP L 2 Replies Last reply
    0
    • E econy

      I met a weird DrawText() blinking problem. in a loop, interval is 2 seconds, I want to show some messages on a dialog screen. i.e. 0-2 sec, message1; 2-4 sec,message2; 4-6, message3 ... but, now the message shows like: flash message1; 0 sec black screen; flash message2; 2 sec black screen; flash message3; 6 sec. black screen; what I want is : message1; 0-2 sec message2; 2-4 sec message3; 4-6 sec

      void CTestDlg::DrawMsg(LPCTSTR iMsgStr)
      {
      CDC* pDC;
      CRect rect;
      CString MsgStr;
      HDC hDC;
      LOGFONT lf;
      HFONT FontNew, FontOld;

      pDC = GetDC();
      hDC = pDC->GetSafeHdc();

      memset(&lf, 0, sizeof(LOGFONT));
      lf.lfHeight = -14 * GetDeviceCaps(hDC,LOGPIXELSY)/72;
      lf.lfWeight = 0;
      FontNew = CreateFontIndirect(&lf);
      FontOld = (HFONT)SelectObject(hDC,FontNew);

      rect.SetRect(CPoint(274,442), CPoint(514,514));
      SetBkMode(hDC,TRANSPARENT);

      DrawText(hDC,dtcMsgStr,-1,rect,DT_WORDBREAK|DT_LEFT);
      InvalidateRect(rect,FALSE);

      SelectObject(hDC,FontOld);
      DeleteObject(FontNew);
      ReleaseDC(pDC);
      }

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      It goes blank because you call InvalidateRect after you call DrawText, switch them around.

      Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      E 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        It goes blank because you call InvalidateRect after you call DrawText, switch them around.

        Within you lies the power for good - Use it!

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        InvalidateRect(rect,FALSE);
        DrawText(hDC,dtcMsgStr,-1,rect,DT_WORDBREAK|DT_LEFT);

        I tried the above way, same phenomenon

        1 Reply Last reply
        0
        • E econy

          I met a weird DrawText() blinking problem. in a loop, interval is 2 seconds, I want to show some messages on a dialog screen. i.e. 0-2 sec, message1; 2-4 sec,message2; 4-6, message3 ... but, now the message shows like: flash message1; 0 sec black screen; flash message2; 2 sec black screen; flash message3; 6 sec. black screen; what I want is : message1; 0-2 sec message2; 2-4 sec message3; 4-6 sec

          void CTestDlg::DrawMsg(LPCTSTR iMsgStr)
          {
          CDC* pDC;
          CRect rect;
          CString MsgStr;
          HDC hDC;
          LOGFONT lf;
          HFONT FontNew, FontOld;

          pDC = GetDC();
          hDC = pDC->GetSafeHdc();

          memset(&lf, 0, sizeof(LOGFONT));
          lf.lfHeight = -14 * GetDeviceCaps(hDC,LOGPIXELSY)/72;
          lf.lfWeight = 0;
          FontNew = CreateFontIndirect(&lf);
          FontOld = (HFONT)SelectObject(hDC,FontNew);

          rect.SetRect(CPoint(274,442), CPoint(514,514));
          SetBkMode(hDC,TRANSPARENT);

          DrawText(hDC,dtcMsgStr,-1,rect,DT_WORDBREAK|DT_LEFT);
          InvalidateRect(rect,FALSE);

          SelectObject(hDC,FontOld);
          DeleteObject(FontNew);
          ReleaseDC(pDC);
          }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You should not be calling InvalidateRect in the same place as you are drawing to the screen. That call is to tell windows that your window needs to be updated, but you are already inside the code where the update is happening. You could simplify this by using one of the standard window controls[^].

          E 2 Replies Last reply
          0
          • L Lost User

            You should not be calling InvalidateRect in the same place as you are drawing to the screen. That call is to tell windows that your window needs to be updated, but you are already inside the code where the update is happening. You could simplify this by using one of the standard window controls[^].

            E Offline
            E Offline
            econy
            wrote on last edited by
            #5

            In fact, I try to use a CEdit first, like:

            //dialog template
            LTEXT "N/A" IDC_TEST_MSG 88,189,128,24 //in resource file,
            //CPP file
            CEdit* pEdit1 = GetDlgItem(IDC_TEST_MSG);
            CDC* pEdit1DC = pEdit1.GetDC();
            pEdit1DC->DrawText()

            But, I got same phenomenon.

            L 1 Reply Last reply
            0
            • E econy

              In fact, I try to use a CEdit first, like:

              //dialog template
              LTEXT "N/A" IDC_TEST_MSG 88,189,128,24 //in resource file,
              //CPP file
              CEdit* pEdit1 = GetDlgItem(IDC_TEST_MSG);
              CDC* pEdit1DC = pEdit1.GetDC();
              pEdit1DC->DrawText()

              But, I got same phenomenon.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              If you are using MFC classes then you should override the OnPaint[^] member function of the class.

              1 Reply Last reply
              0
              • L Lost User

                You should not be calling InvalidateRect in the same place as you are drawing to the screen. That call is to tell windows that your window needs to be updated, but you are already inside the code where the update is happening. You could simplify this by using one of the standard window controls[^].

                E Offline
                E Offline
                econy
                wrote on last edited by
                #7

                then if I want to implement the display effect, what should I do? I want to show: message1 0-2 sec, message2 2-4 sec, message3 4-6 sec, ... I hope it like (calendar time) static text, or text box control in many demo program. that is: 2014/3/15 12:51; 2014/3/15 12:52; 2014/3/15 12:53; update time smoothly.

                L 1 Reply Last reply
                0
                • E econy

                  then if I want to implement the display effect, what should I do? I want to show: message1 0-2 sec, message2 2-4 sec, message3 4-6 sec, ... I hope it like (calendar time) static text, or text box control in many demo program. that is: 2014/3/15 12:51; 2014/3/15 12:52; 2014/3/15 12:53; update time smoothly.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Use something like a progress dialog.

                  E 1 Reply Last reply
                  0
                  • L Lost User

                    Use something like a progress dialog.

                    E Offline
                    E Offline
                    econy
                    wrote on last edited by
                    #9

                    No such thing, it is an embedded Win CE platform

                    L 1 Reply Last reply
                    0
                    • E econy

                      No such thing, it is an embedded Win CE platform

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Pity you did not mention that at the beginning.

                      E 1 Reply Last reply
                      0
                      • L Lost User

                        Pity you did not mention that at the beginning.

                        E Offline
                        E Offline
                        econy
                        wrote on last edited by
                        #11

                        write a test program in a MFC PC program. Now I think I can use a control, like text box to implement my job. but I am still wonder how can I use CRect/DrawText() to implement the same job.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups