I'm writing my own control. It contains the caret. I use the SetCaretPos() function to move the caret. And it works well when I move the caret inside the window:

But when I set a negative y-coordinate for SetCaretPos(), the caret is drawn outside the control window:
SetCaretPos(10, -5);

Then I used IntersectClipRect() function to create new clipping region:
RECT rcClip, rcClient; GetClientRect(hEditWnd_MultyLine, &rcClient); CopyRect(&rcClip, &rcClient); rcClip.left += 2;//add left margin rcClip.right -= 2;//add right margin rcClip.top += 2;//add top margin rcClip.bottom -= 2;//add bottom margin HDC _hdc = GetDC(mywnd_hwnd); IntersectClipRect(_hdc, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); ReleaseDC(mywnd_hwnd, _hdc); And it works fine only for graphics operations like FillRect(), but it has no effect on the caret drawing - there is no caret clipping:

My question is - how to clip caret drawing when its y-coordinate is negative? I need this:

Источник: https://stackoverflow.com/questions/780 ... -the-caret
Мобильная версия