MFC学习笔记四 用鼠标设定文字显示开始位置
来源:互联网 发布:windows测试udp端口 编辑:程序博客网 时间:2024/06/07 03:00
目标:在笔记三的基础上,设定文字开始位置
一、建立单文档的工程,取名mouse,其他同笔记三
二、增加两个变量记录文字显示开始的位置
class CMouseView : public CView{protected: // create from serialization onlyCMouseView();DECLARE_DYNCREATE(CMouseView) boolean Flag;//插入点是否建立的标志 CPoint CaretPosition;//插入点位置 int x,y;//记录文字显示开始的位置// Attributesx,y也需要在构造函数中初始化
CMouseView::CMouseView(){// TODO: add construction code here Flag=false;//一开头为false,伧建后为true,只伧建一次Caret x=y=0;}
三、建立鼠标左键的消息处理程序
void CMouseView::OnLButtonDown(UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultx=point.x;y=point.y;CMouseDoc * p=GetDocument();ASSERT_VALID(p);p->StringData.Empty();//清空字符串Invalidate();CView::OnLButtonDown(nFlags, point);}
四、修改OnDraw函数
1、textout函数要用x,y代替0,0;2、caret的位置计算要考虑x,y
void CMouseView::OnDraw(CDC* pDC){CMouseDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data here // TODO: add draw code for native data here if (!Flag)//没有伧建过Caret则伧建 { TEXTMETRIC textmetric;//The TEXTMETRIC structure contains basic information about a physical font. pDC->GetTextMetrics(&textmetric);//The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font. CreateSolidCaret(textmetric.tmAveCharWidth/8,textmetric.tmHeight);//Creates a solid rectangle for the system caret and claims ownership of the caret. //The caret shape can be a line or block. //插入点高度为tmHeight,宽度则为tmAveCharWidth的1/8 CaretPosition.x=CaretPosition.y=0;//位置为0,因为一开头没有输入文字,也就没有文字显示 SetCaretPos(CaretPosition);//Sets the position of the caret. ShowCaret();//Shows the caret on the screen at the caret’s current position. Flag=true;//标记做好了,以后不再伧建 } HideCaret();// pDC->TextOut(x,y,pDoc->StringData);//输出字符串StringData CSize charsize=pDC->GetTextExtent(pDoc->StringData);//计算尺寸,注意是两个方向的! CaretPosition.x=x+charsize.cx;//CaretPosition.y=y; SetCaretPos(CaretPosition);// ShowCaret();// }
0 0
- MFC学习笔记四 用鼠标设定文字显示开始位置
- opencv学习笔记11 在图片中添加文字,点击鼠标显示位置坐标
- MFC视图实时显示鼠标位置实现
- MFC视图实时显示鼠标位置实现
- MFC学习笔记(四)
- 怎么在在视图中显示鼠标位置 mfc
- MFC:在状态栏上显示鼠标当前的位置
- ios学习笔记:设置UIButton的文字显示位置、字体的大小、字体的颜色
- OpenGL学习笔记:文字显示
- MFC学习笔记之四(音乐,文字输出,障碍物,弹窗)
- VC++/MFC学习笔记(四)
- MFC学习笔记(四)
- MFC学习笔记(四)
- 鼠标经过显示文字
- 显示鼠标坐标位置
- 状态栏显示鼠标位置
- html5-----显示鼠标位置
- vb显示鼠标位置
- jsp对应list做非空判断
- binary search tree
- Unity3D移动端内存优化(NGUI方面)
- 自然语言处理(NLP)网上资源整理3
- thinkphp 如何给控制器传值,实现按钮删除数据库信息
- MFC学习笔记四 用鼠标设定文字显示开始位置
- 求a+b的程序
- 源码分析Fragmentd的BackStack管理过程
- 使用matlab时,将C++编译成matlab时出现错误
- C/C++获取当前系统时间
- http://blog.csdn.net/xiancaifu/article/details/6076289
- linux 学习之路----编译
- 多区域显示(5)-粘贴为图片链接
- 四个步骤实现在ESRI ArcMap中加载17.6G离线卫星地图的方法