当前位置:IT教程网教程中心程序开发C++Builder → 教程内容

VC++讲座笔记-(5)文本编程

减小字体 增大字体 作者:佚名  来源:不详  发布时间:2006-12-31 11:38:00

1,创建插入符:
void CreateSolidCaret( int nWidth, int nHeight );//创建插入符
void CreateCaret( CBitmap* pBitmap );//创建位图插入符
void ShowCaret( );//显示插入符
void HideCaret( );//隐藏插入符
static void PASCAL SetCaretPos( POINT point );//移动插入符号
说明:
1)创建插入符要在窗口创建完成之后,CreateSolidCaret函数创建的插入符被初始化为隐藏,所以需要调用ShowCaret()将其显示。
2)使用CreateCaret函数创建位图插入符的时候,不能使用局部的位图对象关联位图资源。(与资源相关联的C++对象,当它析构的时候会同时把与它相关联的资源销毁。)

2,获取当前字体信息的度量:CDC::GetTextMetrics
BOOL GetTextMetrics( LPTEXTMETRIC lpMetrics ) const;
说明:
typedef struct tagTEXTMETRIC {  /* tm */
    int  tmHeight;//字体高度。Specifies the height (ascent + descent) of characters.
    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;

3,OnDraw函数:
virtual void OnDraw( CDC* pDC )
当窗口(从无到有或尺寸大小改变等)要求重绘的时候,会发送WM_PAIN消息,调用OnDraw函数进行重绘。

4,获取字符串的高度和宽度(区别字符串的长度):
CDC::GetTextExtent
CSize GetTextExtent( LPCTSTR lpszString, int nCount ) const;
CSize GetTextExtent( const CString& str ) const;
说明:
The CSize class is similar to the Windows SIZE structure。
typedef struct tagSIZE {
    int cx;//the x-extent
    int cy;//the y-extent
} SIZE;


5,路径层:
BOOL BeginPath( );
//在这作图定义路径层剪切区域
BOOL EndPath( );
BOOL SelectClipPath( int nMode );//调用这个函数来使当前路径层剪切区域与新剪切区域进行互操作。  
//在这覆盖作图(包含前定义的路径层区域)定义新的剪切区域

说明:
1)SelectClipPath Selects the current path as a clipping region for the device context, combining the new region with any existing clipping region by using the specified mode. The device context identified must contain a closed path.
////
nMode:RGN_AND,RGN_COPY,RGN_DIFF,RGN_OR,RGN_XOR
RGN_AND   The new clipping region includes the intersection (overlapping areas) of the current clipping region and the current path.
RGN_COPY   The new clipping region is the current path.
RGN_DIFF   The new clipping region includes the areas of the current clipping region, and those of the current path are excluded.
RGN_OR   The new clipping region includes the union (combined areas) of the current clipping region and the current path.

本新闻共2页,当前在第1页  1  2  

广告位置