티스토리 뷰
BOOL CreateCaret(HWND hWnd, HBITMAP hBitmap, int nWidth, int nHieght)
BOOL ShowCaret(HWND hWnd)
BOOL HideCaret(HWND hWnd)
BOOL SetCaretPos(intX, int Y)
BOOL DestroyCaret(VOID)
BOOL GetTextExtentPoint(HDC hdc,
LPCTSTR 입력중인 문자열 포인터,
int 문자열수,
LPSIZE 얻어올문자열정보)
static int pos = 0;
SIZE size;
static char strChar[MAX_PATH];
case WM_SETFOCUS:
CreateCaret(hWnd, NULL, 2, 14);
ShowCaret(hWnd);
SetCaretPos(100, 100);
break;
case WM_KILLFOCUS:
HideCaret(hWnd);
DestroyCaret();
break;
case WM_CHAR:
int nlen = strlen(strChar);
strChar[nLen] = (char)wparam;
strChar[nLen+1] = 0;
pos++;
HDC hdc = GetDC(hWnd);
GetTextExtentPoint(hdc, strChar, pos, &size); // 문자열 넓이와 높이얻어 szie에 저장
ReleaseDC(hWnd, hdc);
SetCaretPos(szie.cx + 100, 100); // 캐럿 위치를 문자열 끝으로 이동
InvalidateRect(hWnd, NULL, FALSE);
break;
case WM_PAINT:
HDC hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, 100, 100, strChar, strlen(strChar));
EndPaint(hWnd, &ps);
break;