设为首页 加入收藏

TOP

MFC文本编程:创建插入符
2014-11-13 08:15:06 】 浏览:6600
Tags:MFC 文本 编程 创建 插入

  一、创建文本插入符


  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);


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C/C++语言中Static的作用详述 下一篇MFC绘图:显示位图

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目