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:




Afaik, you can't do it that simply. Clipping region is part of GDI and caret belongs to the "window" - the native control.
Judging by what WinForms and C# offer, I think there are several ways to do so: