[连载]VC++深入详解(孙鑫视频)第5章-文本编程 笔记

一、插入符(caret)的创建

1.CWnd::CreateSolidCaret 

void CreateSolidCaret( int nWidth, int nHeight );

Parameters

nWidth

Specifies the width of the caret (in logical units). If this parameter is 0, the width is set to the system-defined window-border width.

nHeight

Specifies the height of the caret (in logical units). If this parameter is 0, the height is set to the system-defined window-border height.

Remarks

Creates a solid rectangle for the system caret and claims ownership of the caret. The caret shape can be a line or block.

The parameters nWidth and nHeight specify the caret’s width and height (in logical units); the exact width and height (in pixels) depend on the mapping mode.

The system’s window-border width or height can be retrieved by the GetSystemMetrics Windows function with the SM_CXBORDER and SM_CYBORDER indexes. Using the window-border width or height ensures that the caret will be visible on a high-resolution display.

The CreateSolidCaret member function 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 member function must be called.

The system caret is a shared resource. CWnd should create a caret only when it has the input focus or is active. It should destroy the caret before it loses the input focus or becomes inactive.

注意几点:

(1).插入符应该创建在视类中,在视类窗口产生后。在视类中增加WM_CREATE消息的响应函数OnCreate中

(2).如果 nWidth 和 nHeight 是 0, 那么插入符的宽度和高度被设置成系统定义窗口边界的宽度和高度,也可以调用 int GetSystemMetrics( int nIndex );得到系统信息,如GetSystemMetrics(SM_CXBORDER)得到 系统窗口边界宽度。

(3).Once created, the caret is initially hidden(caret被创建后初始是隐藏的,得调用voidCWnd:: ShowCaret( )才能显示。

代码:

int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct)   //在视类中增加WM_CREATE消息的响应函数  

                                                                                                                 //OnCreate()
{
 if (CView::OnCreate(lpCreateStruct) == -1)
  return -1;
 
 // TODO: Add your specialized creation code here
 CreateSolidCaret(GetSystemMetrics(SM_CXBORDER),GetSystemMetrics(SM_CYBORDER)); //得到系统窗口边

                                                                                                                                                                           //界宽度和高度ShowCaret();                   //显示插入符
 return 0;
}

 2.如何让插入符适合于当前字体大小?

用CDC类中的GetTextMetrics函数实现,可得到设备描述表中当前字体的度量信息,并存放到TEXTMETRIC机构体变量中。

typedef struct tagTEXTMETRIC {  /* tm */
    int  tmHeight;                 //当前字符字体的高度
    int  tmAscent;
    int  tmDescent;
    int  tmInternalLeading;
    int  tmExternalLeading;
    int  tmAveCharWidth;           //当前文本字体的平均宽度
    int  tmMaxCharWidth;
    int  tmWeight;               
    BYTE tmItalic;
    BYTE tmUnderlined;
    BYTE tmStruckOut;
    BYTE tmFirstChar;
    BYTE tmLastChar;
    BYTE tmDefaultChar;
    BYTE tmBreakChar;
    BYTE tmPitchAndFamily;
    BYTE tmCharSet;
    int  tmOverhang;
    int  tmDigitizedAspectX;
    int  tmDigitizedAspectY;
} TEXTMETRIC;
代码如下:
int CTextView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
 if (CView::OnCreate(lpCreateStruct) == -1)
  return -1;
 
 // TODO: Add your specialized creation code here
 TEXTMETRIC tm;
 CClientDC dc(this);
 dc.GetTextMetrics(&tm);
 CreateSolidCaret(tm.tmAveCharWidth/8,tm.tmHeight); //除8是经验值
 ShowCaret();
 return 0;
}
3.创建图形插入符
用函数void CreateCaret(CBitmap* pBitmap);实现。
注意一点:位图变量要定义为CTextViww类的成员变量,不能定义为局部变量,否则不行显示。
孙鑫vc是一种特殊的混合编程语言,它结合了C语言和Verilog语言的特点。在深入详解孙鑫vc代码之前,我们先了解一下它的一些特性。 首先,孙鑫vc具有高度的可定制性。用户可以根据自己的需求选择C语言和Verilog语言中的特性来编写代码。这种灵活性使得孙鑫vc可以适用于不同的应用领域。 其次,孙鑫vc支持并行计算。它提供了一种简单而有效的方式来利用硬件资源进行并行计算,提高程序的执行效率。 另外,孙鑫vc还具有强大的调试功能。它能够在运行时对代码进行监控和调试,帮助开发者快速定位问题并进行修复。 深入详解孙鑫vc代码包括以下几个方面: 首先,我们可以从代码的结构和组织方式入手。孙鑫vc代码一般由多个模块组成,每个模块包含了各自的功能和接口。 其次,我们需要了解代码中使用的变量和数据类型。在孙鑫vc中,可以使用C语言和Verilog语言中的数据类型,如整型、浮点型等。了解这些数据类型的使用方法和限制对理解代码非常重要。 然后,我们需要分析代码中的控制流和算法。这包括了代码中的条件语句、循环语句等,以及算法的实现细节。通过对控制流和算法的分析,我们可以更好地理解代码的逻辑和实现原理。 最后,我们还需要关注代码中的接口和数据传输方式。在孙鑫vc中,模块之间通过接口进行数据的传递和交互。了解接口的定义和使用方式对于理解代码的功能和模块之间的关系非常重要。 综上所述,深入详解孙鑫vc代码需要从代码的结构和组织方式、变量和数据类型、控制流和算法、接口和数据传输方式等多个方面进行分析和理解。通过对这些方面的研究,我们可以更好地理解孙鑫vc代码,并且能够对代码进行修改和优化。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值