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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. validateRect within CDialogBar

validateRect within CDialogBar

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpannouncement
4 Posts 2 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.
  • I Offline
    I Offline
    IlanTal
    wrote on last edited by
    #1

    I have a strange problem within a CDialogBar. I need to paint some text in a different font, so I used a static box which I paint over. I capture the WM_PAINT message as OnPaint(). What I intended to do was invalidate the static box to cause a paint command, then inside the SetPatInfo() routine (inside the paint), validate the static box. There seems to be a timing problem as first my routine draws to the box and then another message comes along which updates the static box. I can verify this by making the CDialogBar disappear from the screen and then reappear, in which case there is no invalid area and just my update is performed under the OnPaint(). I went farther to prove it by invalidating just 1/2 of the box in which case only 1/2 of the box is overwritten after I update it. My question is: why doesn't validateRect stop the second update and where is the second update coming from? A solution to the problem is to update a single pixel in the corner of the box, but I want to know what is going on and why. Here are some code snippets: void CMyToolbar::OnPaint() { CPaintDC dc(this); // device context for painting SetPatInfo(); } void CMyToolbar::Invalidate(void) { CWnd *wnd1; CRect rc1; wnd1 = GetDlgItem(IDC_PATINFO); wnd1->GetClientRect(&rc1); rc1.right /= 2; // for test, invalid 1/2 of rectangle wnd1->InvalidateRect(rc1,0); } void CMyToolbar::SetPatInfo(void) { ..... wnd1 = GetDlgItem(IDC_PATINFO); pDC = wnd1->GetDC(); ..... wnd1->GetClientRect(&rc1); wnd1->ValidateRect(NULL); // NULL validates the whole window sz1.cx = rc1.right; sz1.cy = rc1.bottom; br1.CreateSolidBrush(bkgColor); pDC->FillRect(rc1, &br1); ..... } Any suggestions to telling me what is going on here would be appreciated. Ilan

    P I 2 Replies Last reply
    0
    • I IlanTal

      I have a strange problem within a CDialogBar. I need to paint some text in a different font, so I used a static box which I paint over. I capture the WM_PAINT message as OnPaint(). What I intended to do was invalidate the static box to cause a paint command, then inside the SetPatInfo() routine (inside the paint), validate the static box. There seems to be a timing problem as first my routine draws to the box and then another message comes along which updates the static box. I can verify this by making the CDialogBar disappear from the screen and then reappear, in which case there is no invalid area and just my update is performed under the OnPaint(). I went farther to prove it by invalidating just 1/2 of the box in which case only 1/2 of the box is overwritten after I update it. My question is: why doesn't validateRect stop the second update and where is the second update coming from? A solution to the problem is to update a single pixel in the corner of the box, but I want to know what is going on and why. Here are some code snippets: void CMyToolbar::OnPaint() { CPaintDC dc(this); // device context for painting SetPatInfo(); } void CMyToolbar::Invalidate(void) { CWnd *wnd1; CRect rc1; wnd1 = GetDlgItem(IDC_PATINFO); wnd1->GetClientRect(&rc1); rc1.right /= 2; // for test, invalid 1/2 of rectangle wnd1->InvalidateRect(rc1,0); } void CMyToolbar::SetPatInfo(void) { ..... wnd1 = GetDlgItem(IDC_PATINFO); pDC = wnd1->GetDC(); ..... wnd1->GetClientRect(&rc1); wnd1->ValidateRect(NULL); // NULL validates the whole window sz1.cx = rc1.right; sz1.cy = rc1.bottom; br1.CreateSolidBrush(bkgColor); pDC->FillRect(rc1, &br1); ..... } Any suggestions to telling me what is going on here would be appreciated. Ilan

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      try Validating the rect after completing drawing operation i.e. call ValidateRect after calling FillRect.

      Prasad Notifier using ATL

      1 Reply Last reply
      0
      • I IlanTal

        I have a strange problem within a CDialogBar. I need to paint some text in a different font, so I used a static box which I paint over. I capture the WM_PAINT message as OnPaint(). What I intended to do was invalidate the static box to cause a paint command, then inside the SetPatInfo() routine (inside the paint), validate the static box. There seems to be a timing problem as first my routine draws to the box and then another message comes along which updates the static box. I can verify this by making the CDialogBar disappear from the screen and then reappear, in which case there is no invalid area and just my update is performed under the OnPaint(). I went farther to prove it by invalidating just 1/2 of the box in which case only 1/2 of the box is overwritten after I update it. My question is: why doesn't validateRect stop the second update and where is the second update coming from? A solution to the problem is to update a single pixel in the corner of the box, but I want to know what is going on and why. Here are some code snippets: void CMyToolbar::OnPaint() { CPaintDC dc(this); // device context for painting SetPatInfo(); } void CMyToolbar::Invalidate(void) { CWnd *wnd1; CRect rc1; wnd1 = GetDlgItem(IDC_PATINFO); wnd1->GetClientRect(&rc1); rc1.right /= 2; // for test, invalid 1/2 of rectangle wnd1->InvalidateRect(rc1,0); } void CMyToolbar::SetPatInfo(void) { ..... wnd1 = GetDlgItem(IDC_PATINFO); pDC = wnd1->GetDC(); ..... wnd1->GetClientRect(&rc1); wnd1->ValidateRect(NULL); // NULL validates the whole window sz1.cx = rc1.right; sz1.cy = rc1.bottom; br1.CreateSolidBrush(bkgColor); pDC->FillRect(rc1, &br1); ..... } Any suggestions to telling me what is going on here would be appreciated. Ilan

        I Offline
        I Offline
        IlanTal
        wrote on last edited by
        #3

        Ovidiu answered my question in previous question which I unfortunately didn't see until after posting this message. His answer is: As long as you have not handled WM_PAINT in the static control, but you draw text in it from another place, for sure you'll have troubles after another window will overlap; just test it and see if I'm right. Ovidiu He is ABSOLUTELY right and now I have to figure out how I can handle just the WM_PAINT for that static control. I see a WM_PAINT for the DialogBar but I can't find a separate one for just the static control. BTW, in answer to my response, it makes no difference if I do the validateRect before or after the FillRect. I'm sure Ovidiu is on the right track, but I just have to figure out how to do it.

        P 1 Reply Last reply
        0
        • I IlanTal

          Ovidiu answered my question in previous question which I unfortunately didn't see until after posting this message. His answer is: As long as you have not handled WM_PAINT in the static control, but you draw text in it from another place, for sure you'll have troubles after another window will overlap; just test it and see if I'm right. Ovidiu He is ABSOLUTELY right and now I have to figure out how I can handle just the WM_PAINT for that static control. I see a WM_PAINT for the DialogBar but I can't find a separate one for just the static control. BTW, in answer to my response, it makes no difference if I do the validateRect before or after the FillRect. I'm sure Ovidiu is on the right track, but I just have to figure out how to do it.

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          quite right. I think you need to override CStatic class to use in you app.

          Prasad Notifier using ATL

          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