文档详情

VisualC++面向对象与可视化程序设计04.ppt

发布:2017-04-22约字共36页下载文档
文本预览下载声明
第4讲 文本与字体;5.1 设置文本的设备环境;(1) 定义字体句柄变量: HFONT hF; //hF为字体的句柄;5.1.2 创建自定义字体;5.1.3 设置字体和背景颜色;5.2 文本的输出过程;获取字体信息;系统定义的TEXTMETRICS的结构如下: typedef struct tagTEXTMETRIC { //tm LONG tmHeight; //字符高度 LONG tmAscent; //字符基线以上高度 LONG tmDescent; //字符基线以下高度 LONG tmInternalLeading; //tmHeight制订的字符高度顶部的控件 LONG tmExternalLeading; //行与行之间的间隔 LONG tmAveCharWidth; //平均字符宽度 LONG tmMaxCharWidth; //最大字符宽度 LONG tmWeight; //字符的粗细度 LONG tmOverhang; //合成字体间附加的宽度 LONG tmDigitizedAspectX; //为输出设备设计的X轴尺寸 LONG tmDigitizedAspectY; //为输出设备设计的Y轴尺寸 BCHAR tmFirstChar; //字体中第一个字符值 BCHAR tmLastChar; //字体中最后一个字符值 BCHAR tmDefaultChar; //代替不在字体中字符的字符 BCHAR tmBreakChar; //作为分割符的字符 BYTE tmItalic; //非0则表示字体为斜体 BYTE tmUnderlined; //非0则表示字体有下划线 BYTE tmStruckOut; //非0则表示字符为删除字体 BYTE tmPitchAndFamily; //字体间距和字体族 BYTE tmCharSet; //字符集 }TEXTMETRIC;格式化文本;(2)确定换行时文本坐标;文本输出;5.3 文本操作实例;//主函数 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG Message; if(!InitWindowsClass(hInstance)) return FALSE; if(!InitWindows(hInstance,nCmdShow))return FALSE; while(GetMessage(Message,0,0,0))//消息循环 { TranslateMessage(Message); DispatchMessage(Message); } return Message.wParam; };//消息处理函数 long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam) { static long nXChar,nCaps,nYChar; HDC hDC; //定义指向设备上下文的句柄 short x; TEXTMETRIC tm; short LnCount=6; PAINTSTRUCT PtStr; //定义指向包含绘图信息的结构体变量 static char *textbuf[]= { This is the First line, This is the second line, This is the third line, This is the fourth line, This is the fifth line, This is the sixth line };;switch(iMessage) //处理消息 {case WM_CREATE: //处理窗口创建消息 hDC=GetDC(hWnd) ; //获取当前设备表句柄 GetTextMetrics(hDC,tm); //获取字体信息 nXChar=tm.tmAveCharWidth; //获取字符宽度 nYChar=tm.tmHeight+tm.tmExternalLeading; nCaps=(tm.tmPitchAndFamily1?3:2)*nXChar/2; ReleaseDC(hWnd,hDC); //释放当前设备句柄 return 0; case WM
显示全部
相似文档