question

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

Visual C++ MFC CScrollView: caret stops flashing

My English is not perfect. I am using Visual C++ 2019 16.9.3 Community Edition with MFC, AMD64 Release. Single-document and multiple-document programs are concerned so. Example program: a single-document program.

Base of View class is CScrollView. The caret flashs only some seconds, after it, stops flashing.

 void CsdView::OnDraw(CDC *pDC) {
     HideCaret();
     CPoint  const pos = GetDeviceScrollPosition();
     CRect rect;
     GetClientRect(&rect);
     OffsetRect(&rect, pos.x, pos.y);
     pDC->FillSolidRect(rect, 0xFFFFFF);
     CFont   font;
     font.CreatePointFont(90, L"Consolas");
     const auto  oldfont = pDC->SelectObject(&font);
     wchar_t a[12];
     for (int y = (pos.y / 54) * 54; y < rect.bottom; y += 54)
         pDC->TextOutW(8, y, _itow(y, a, 10));
     pDC->SelectObject(oldfont);
     ShowCaret();
 }
    
 void CsdView::OnInitialUpdate() {
     CScrollView::OnInitialUpdate();
     CScrollView::SetScrollSizes(MM_TEXT, { 2560, 40000 });
 }
    
 BOOL CsdView::OnEraseBkgnd(CDC *) {
     return  TRUE;
 }
    
 void CsdView::OnSize(UINT nType, int x, int y) {
     CScrollView::OnSize(nType, x, y);
     SetScrollSizes(MM_TEXT,
         {2560, 40000},
         {(x/20)*20, (y/54)*54},
         {20, 54});
 }
    
 void CsdView::OnSetFocus(CWnd *pOldWnd) {
     CScrollView::OnSetFocus(pOldWnd);
     CreateSolidCaret(4, 48);
     SetCaretPos({0, 0});
     ShowCaret();
 }
    
 void CsdView::OnKillFocus(CWnd *pNewWnd) {
     CScrollView::OnKillFocus(pNewWnd);
     HideCaret();
 }

I am using a high DPI monitor, there is 3 * 96 dpi = 288 dpi at setting in Windows.

c++
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.

1 Answer

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

The same behaviour can be observed for other programs, such as Notepad, or various fields of system dialogs. It seems that there is a system-wide configuration parameter: https://www.bing.com/search?q=CaretTimeout+OR+SPI_SETCARETTIMEOUT. The limitation was probably added purposely.

If for some reason you do not like the recommended behaviour, maybe create a timer, using an interval that depends on setting values, handle WM_TIMER, call HideCaret and ShowCaret. Stop the timer if the view is unfocused.

· 2
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.

Thank you. 5.5 second was the best.

https://developercommunity.visualstudio.com/t/Scrollbar-jumping-back-in-CScrollView/1388437

Does this a Windows functionality so? How can I disable? The base of the View class is CScrollView. For example, if the height of the view is 40 000 pixels, and I scroll the vertical scrollbar with mouse from the begin (position 0) to the end (position after 32 768) in 1 step (in 1 mouse-move), the scrollbar jumps back to the begin of the view: to position 0.

0 Votes 0 ·

Because of Epilepsy? I deleted the timer, will stops after 5 seconds. (I have not epilepsy).

0 Votes 0 ·