question

ZoltnHegeds-7054 avatar image
0 Votes"
ZoltnHegeds-7054 asked ZoltnHegeds-7054 action

CScrollView does not repaint the whole area

My IDE shows the pair of () {} [] at the caret: for example, if the character at the caret is (, shows ) with different background. For example, if I press Caret Down, when the caret is on the last visible line, scrolls 1 line with ScrollToPosition. This calls OnDraw, what repaint the whole visible area, but CScrollView uses only the last line form this: on the other part of the window, scrolls the original content. So, the caret moved, but the highlighting of the pair of the bracket remains: will be a lot of highlighted characters.

c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried to note the position, color, and the character, and write to the display before scrolling.

     CPoint    pos = GetDeviceScrollPosition();
     if (bp) {
         CDC    *const pDC = GetWindowDC();
         const auto    oldfont = pDC->SelectObject(&font);
         pDC->SetBkMode(OPAQUE);
         pDC->SetBkColor(bpbkc);
         pDC->SetTextColor(bpc);
         pDC->TextOutW(bpx - pos.x, bpy - pos.y, &bp, 1);
         pDC->SelectObject(oldfont);
         ReleaseDC(pDC);
     }

This works, but does required? Can I disable the optimisation? Only when I overwrite before OnDraw (before OnDraw, on inside OnDraw, using GetWindowDC instead of the parameter of OnDraw) ?

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered ZoltnHegeds-7054 commented

In my opinion, when you want to modify something in your view, you should call InvalidateRect or InvalidateRgn for all of changed areas, store the new data, and let the OnPaint or OnDraw handlers to draw the new image using the current data. This will also work when you, for example, minimise and restore the window, which requires repainting too.

You do not have to draw new characters explicitly. Try calling InvalidateRect two times: for un-highlighted and highlighted characters. Perform the drawing inside the OnDraw only using the supplied pDC.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.