Even though I changed the WM_SETFOCUS section of the code under the “Processing Keyboard Input” heading in the link below to use a bitmap for caret, I cannot get any caret image on the screen and no error message from CreateCaret() function. I have checked that the code created a bitmap or not.
https://learn.microsoft.com/tr-tr/windows/win32/menurc/using-carets
case WM_SETFOCUS:
{
int caret_width = (nCharX/5)>=2 ? nCharX/5 : 2;
RECT rcCaret = { 0, 0, caret_width, nCharY };
hdc = GetDC(hwnd);
HBITMAP hBitmapNew = CreateCompatibleBitmap(hdc, caret_width, nCharY);
HDC hdcMemNew = CreateCompatibleDC(hdc);
SelectObject(hdcMemNew, hBitmapNew);
HBRUSH caretBrush = CreateSolidBrush(RGB(255,0,0));
FillRect(hdcMemNew, &rcCaret, caretBrush);
if(CreateCaret(hwnd, (HBITMAP) hBitmapNew, 0, 0)==0) {
MessageBox(NULL, "CreateCaret() error!", "Error", MB_OK) ;
}
// CreateCaret(hwnd, 0, nCharX, nCharY); // Adjust the caret position.
SetCaretPos(nCaretPosX * nCharX, nCaretPosY * nCharY); // Display the caret.
ShowCaret(hwnd);
DeleteObject(caretBrush);
DeleteObject(hdcMemNew);
DeleteObject(hBitmapNew);
ReleaseDC(hwnd, hdc);
}
break;
I tried to change caret bitmap, but no caret image on the window.
New contributor
Niteya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.