分享
 
 
 

旋转的文本

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

<!--StartFragment-->在VB中利用Windows的API函数可以实现很多的VB无法实现的扩展功能,下面的程序介绍的是如何通过调用Windows中的API函数实现文本旋转显示的特级效果。

首先建立一个工程文件,然后选菜单中的Project | Add Class Module 加入一个新的类文件,并将这个类的Name属性改变为APIFont,然后在类的代码窗口中加入以下的代码:

Option Explicit

Private Declare Function SelectClipRgn Lib “gdi32”(ByVal hdc As Long, ByVal hRgn As _

Long) As Long

Private Declare Function CreateRectRgn Lib “gdi32”(ByVal X1 As Long, ByVal Y1 As _

Long, ByVal X2 As Long, ByVal Y2 As Long) As Long

Private Declare Function SetTextColor Lib “gdi32”(ByVal hdc As Long, ByVal crColor As _

Long) As Long

Private Declare Function DeleteObject Lib “gdi32”(ByVal hObject As Long) As Long

Private Declare Function CreateFontIndirect Lib “gdi32” Alias “CreateFontIndirectA” _

(lpLogFont As LOGFONT) As Long

Private Declare Function SelectObject Lib “gdi32”(ByVal hdc As Long, ByVal hObject As _

Long) As Long

Private Declare Function TextOut Lib “gdi32” Alias “TextOutA” (ByVal hdc As Long, _

ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As _

Long) As Long

Private Declare Function SetTextAlign Lib “gdi32”(ByVal hdc As Long, ByVal wFlags _

As Long) As Long

Private Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Private Const TA_LEFT = 0

Private Const TA_RIGHT = 2

Private Const TA_CENTER = 6

Private Const TA_TOP = 0

Private Const TA_BOTTOM = 8

Private Const TA_BASELINE = 24

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 As String * 50

End Type

Private m_LF As LOGFONT

Private NewFont As Long

Private OrgFont As Long

Public Sub CharPlace(o As Object, txt$, X, Y)

Dim Throw As Long

Dim hregion As Long

Dim R As RECT

R.Left = X

R.Right = X + o.TextWidth(txt$) * 2

R.Top = Y

R.Bottom = Y + o.TextHeight(txt$) * 2

hregion = CreateRectRgn(R.Left, R.Top, R.Right, R.Bottom)

Throw = SelectClipRgn(o.hdc, hregion)

Throw = TextOut(o.hdc, X, Y, txt$, Len(txt$))

DeleteObject (hregion)

End Sub

Public Sub SetAlign(o As Object, Top, BaseLine, Bottom, Left, Center, Right)

Dim Vert As Long

Dim Horz As Long

If Top = True Then Vert = TA_TOP

If BaseLine = True Then Vert = TA_BASELINE

If Bottom = True Then Vert = TA_BOTTOM

If Left = True Then Horz = TA_LEFT

If Center = True Then Horz = TA_CENTER

If Right = True Then Horz = TA_RIGHT

SetTextAlign o.hdc, Vert Or Horz

End Sub

Public Sub setcolor(o As Object, CValue As Long)

Dim Throw As Long

Throw = SetTextColor(o.hdc, CValue)

End Sub

Public Sub SelectOrg(o As Object)

Dim Throw As Long

NewFont = SelectObject(o.hdc, OrgFont)

Throw = DeleteObject(NewFont)

End Sub

Public Sub SelectFont(o As Object)

NewFont = CreateFontIndirect(m_LF)

OrgFont = SelectObject(o.hdc, NewFont)

End Sub

Public Sub FontOut(text$, o As Control, XX, YY)

Dim Throw As Long

Throw = TextOut(o.hdc, XX, YY, text$, Len(text$))

End Sub

Public Property Get Width() As Long

Width = m_LF.lfWidth

End Property

Public Property Let Width(ByVal W As Long)

m_LF.lfWidth = W

End Property

Public Property Get Height() As Long

Height = m_LF.lfHeight

End Property

Public Property Let Height(ByVal vNewValue As Long)

m_LF.lfHeight = vNewValue

End Property

Public Property Get Escapement() As Long

Escapement = m_LF.lfEscapement

End Property

Public Property Let Escapement(ByVal vNewValue As Long)

m_LF.lfEscapement = vNewValue

End Property

Public Property Get Weight() As Long

Weight = m_LF.lfWeight

End Property

Public Property Let Weight(ByVal vNewValue As Long)

m_LF.lfWeight = vNewValue

End Property

Public Property Get Italic() As Byte

Italic = m_LF.lfItalic

End Property

Public Property Let Italic(ByVal vNewValue As Byte)

m_LF.lfItalic = vNewValue

End Property

Public Property Get UnderLine() As Byte

UnderLine = m_LF.lfUnderline

End Property

Public Property Let UnderLine(ByVal vNewValue As Byte)

m_LF.lfUnderline = vNewValue

End Property

Public Property Get StrikeOut() As Byte

StrikeOut = m_LF.lfStrikeOut

End Property

Public Property Let StrikeOut(ByVal vNewValue As Byte)

m_LF.lfStrikeOut = vNewValue

End Property

Public Property Get FaceName() As String

FaceName = m_LF.lfFaceName

End Property

Public Property Let FaceName(ByVal vNewValue As String)

m_LF.lfFaceName = vNewValue

End Property

Private Sub Class_Initialize()

m_LF.lfHeight = 30

m_LF.lfWidth = 10

m_LF.lfEscapement = 0

m_LF.lfWeight = 400

m_LF.lfItalic = 0

m_LF.lfUnderline = 0

m_LF.lfStrikeOut = 0

m_LF.lfOutPrecision = 0

m_LF.lfClipPrecision = 0

m_LF.lfQuality = 0

m_LF.lfPitchAndFamily = 0

m_LF.lfCharSet = 0

m_LF.lfFaceName = "Arial" + Chr(0)

End Sub

在工程文件的Form1中加入一个PictureBox和一个CommandButton控件,然后在Form1的代码窗口中加入以下的代码:

Option Explicit

Dim AF As APIFont

Dim X, Y As Integer

Private Sub Command1_Click()

Dim i As Integer

Set AF = Nothing

Set AF = New APIFont

Picture2.Cls

For i = 0 To 3600 Step 360

AF.Escapement = i

AF.SelectFont Picture2

X = Picture2.ScaleWidth / 2

Y = Picture2.ScaleHeight / 2

'在字符串后面要加入7个空格

AF.FontOut “电脑商情报第42期 ”, Picture2, X, Y

AF.SelectOrg Picture2

Next i

End Sub

Private Sub Form_Load()

Picture2.ScaleMode = 3

End Sub

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有