Visual C++ MFC CScrollView: caret stops flashing

87 Views Asked by At

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.

0

There are 0 best solutions below