一、创建文本插入符
Step01、创建插入符
相关函数/结构体
CWnd::CreateSolidCaret();
定义:void CreateSolidCaret(int nWidth,int nHeight);
在View类中加入WM_CREATE消息的响应函数OnCreate,加入CreateSolidCaret()
效果:没有显示插入符呀!
QUOTE FROM MSDN
The CreateSolidCaret method automatically destroys the previous caret shape, if any, regardless of which window owns the caret. Once created, the caret is initially hidden. To show the caret, the ShowCaret method must be called.
Step02、显示插入符
加上ShowCaret();
Step03、让插入符跟字体大小相关
相关函数/结构体:
获取字符信息CDC::GetTextMetrics
字符属性结构体TEXTMETRIC Structure
code
/////////////////////////////////////////////////////////////////////////////
// CTextView message handlers
int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
//创建设备描述表
CClientDC dc(this);
//定义文本信息结构体变量
TEXTMETRIC tm;
//获得设备描述表中的文本信息
dc.GetTextMetrics(&tm);
//根据字体大小,创建合适的插入符
CreateSolidCaret(tm.tmAveCharWidth/8, tm.tmHeight);