今天参考一个外文代码写的:
(作者:Steve McMahon steve@vbaccelerator.com,
网址: http://www.shitalshah.com/vbxlr/tips/vba0035.htm )
Private Const LF_FACESIZE = 32
Private Const FW_NORMAL = 400
Private Const FW_BOLD = 700
Private Const FF_DONTCARE = 0
Private Const DEFAULT_QUALITY = 0
Private Const DEFAULT_PITCH = 0
Private Const DEFAULT_CHARSET = 1
Private Const DT_CALCRECT = &H400
Private Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(LF_FACESIZE) As Byte
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Sub printtext(ByVal hdc As Long, ByVal mystr As String, myfont As StdFont, Optional ByVal fontwidth As Integer = 30, Optional ByVal fontheight As Integer = 15, Optional ByVal fontbold As Boolean = False, Optional ByVal fontitlaic As Boolean = False, Optional ByVal fontunderline As Boolean = False, Optional ByVal fontStrikethrough As Boolean = False)
Dim tLF As LOGFONT
Dim hFnt As Long
Dim hFntOld As Long
Dim tR As RECT
Dim sFont As String
Dim iChar As Integer
Dim temp() As Byte
' Convert an OLE StdFont to a LOGFONT structure:
With tLF
sFont = myfont.Name
temp = StrConv(sFont, vbFromUnicode)
For iChar = 1 To Len(sFont)
.lfFaceName(iChar - 1) = temp(iChar - 1)
Next iChar
' Based on the Win32SDK documentation:
.lfItalic = myfont.Italic
lfWeight = IIf(myfont.Bold, FW_BOLD, FW_NORMAL)
.lfWidth = fontwidth
.lfHeight = fontheight
.lfUnderline = fontunderline
.lfStrikeOut = fontStrikethrough
.lfCharSet = myfont.Charset
End With
hFnt = CreateFontIndirect(tLF) ' Convert the LOGFONT into a font handle
' Test the font out:
hFntOld = SelectObject(hdc, hFnt)
DrawText hdc, mystr, -1, tR, DT_CALCRECT
OffsetRect tR, 32, 32
DrawText hdc, mystr, -1, tR, 0&
SelectObject hdc, hFntOld
' remember to delete the font when finished
DeleteObject hFnt
End Sub
Private Sub Command1_Click()
Me.Cls
Dim myfont As New StdFont
myfont.Name = "arial"
printtext Me.hdc, "扁扁的几个字", myfont, 50, 20
End Sub
Private Sub Command2_Click()
Dim myfont As New StdFont
myfont.Name = "arial"
printtext Me.hdc, "修长的几个字", myfont, 10, 200, True, True, False, False
End Sub
|
|
<!----> |
输出:
分享到:
相关推荐
- 横向32个LED灯珠称为一列,纵向16个LED灯珠为一行。控制每一列的开关状态,结合行扫描的方式,就能在点阵上显示完整的图像。 2. 控制电路设计: - 为了驱动16X32点阵,通常需要使用驱动芯片,如74HC595,它可以...
- **字体的像素方向**:指明字体是横向还是纵向排列的。 - **字体分辨率**:通常指的是每英寸的点数(DPI),包括水平和垂直分辨率。 - **字符集编码**:字体所使用的字符集编码,例如ASCII或Unicode。 ##### 2. ...
在IT行业中,将静态资源或文件转换为PDF是一种常见的需求,尤其在文档分享、报告制作或网站内容保存等方面。这个工具或技术方案的核心是利用`pdfkit`库,它允许开发者通过简单的API调用来实现HTML到PDF的转换。下面...
表设计优化可以从多个方面进行,包括选择合适的字段类型、聚集索引的选择、表的纵向和横向拆分、数据库分库以及数据压缩的利弊等。 2.1 字段类型的选择优先级 在表设计时,不同的字段类型对性能有不同影响。一般...
在计算机中,字体通常由字库文件(如TrueType或OpenType)存储,这些文件包含了构成每个字符的点阵或曲线数据。当我们在屏幕上显示或打印文字时,操作系统会根据这些数据绘制出相应的字形。 自定义字体宽、高比例,...
- **-b**: 将文件名中不可输出的特殊字符转义为`\`加字符编码形式。 - **-c**: 按文件i节点的最后修改时间排序输出文件列表。 - **-d**: 将目录当作普通文件来显示,而不是列出目录内的内容。 - **-e**: 输出完整的...
- **屏幕分辨率**:显示器在横向和纵向上的点数。 - **图像分辨率**:每英寸长度图像上的像素点数量(dpi)。 - **像素分辨率**:像素的宽和高比例。 ##### 4.2 图像深度与显示深度 - **图像深度**:每个像素点上...
本文将详细介绍如何使用GDI+(Graphics Device Interface Plus)这一图形处理库来实现多张图片横向或纵向排列并整合成一张图片的功能。 #### GDI+简介 GDI+是Microsoft推出的一种用于Windows平台的绘图API,它提供...
- **字符放大与旋转**:字符可以在横向和纵向实现1-6级放大,并能实现四个方向的旋转打印,增强了排版的自由度。 #### 四、打印机的安装与配置 - **安装位置**:选择平整、稳固的地方安装打印机,确保周围有足够的...