利用API 实现 字符串的镜像

本文介绍了一种使用API实现字符串镜像的方法。通过VB编程调用gdi32.dll中的StretchBlt函数,在图片框中绘制文字并进行水平和垂直翻转,实现了文字的镜像效果。

利用API 实现 字符串的镜像(一)

 

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020
Private WithEvents pic1 As PictureBox
Private WithEvents pic2 As PictureBox


Sub Form_Load()
Me.Move 0, 0, 10200, 4000
Set pic1 = Controls.Add("vb.picturebox", "pic1", Me)
pic1.Visible = True
pic1.Move 0, 0, 5000, 2500
Set pic2 = Controls.Add("vb.picturebox", "pic2", Me)
pic2.Visible = True
pic2.Move 5000, 0, 5000, 2500
pic1.ScaleMode = 3
pic2.ScaleMode = 3
End Sub


Sub Form_Click()
pic2.CurrentX = 0
pic2.CurrentY = 0
pic2.FontSize = 120
pic2.ForeColor = vbRed
pic2.FontName = "隶书"
pic2.Print "镜像"
StretchBlt pic1.hdc, pic2.ScaleWidth, 0, -pic2.ScaleWidth, pic2.ScaleHeight, pic2.hdc, 0, 0, pic2.ScaleWidth, pic2.ScaleHeight, SRCCOPY
End Sub

利用API 实现 字符串的镜像(二)

 

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020
Private WithEvents pic1 As PictureBox

Sub Form_Load()
Me.Move 0, 0, 11000, 8500
Set pic1 = Controls.Add("vb.picturebox", "pic1", Me)
With pic1
.Visible = True
.Move 3600, 2700, 3600, 2700
.ScaleMode = 3
.Appearance = 0
.BackColor = Me.BackColor
.CurrentX = 0
.CurrentY = 0
.FontSize = 60
.ForeColor = vbBlue
.FontName = "隶书"
End With
End Sub


Sub Form_Click()
Dim w As Integer, h As Integer
pic1.Print "人之初" & vbCrLf & "性本善"
w = pic1.ScaleWidth
h = pic1.ScaleHeight
StretchBlt Me.hdc, w, h, -w, h, pic1.hdc, 0, 0, w, h, SRCCOPY
StretchBlt Me.hdc, 3 * w, h, -w, h, pic1.hdc, 0, 0, w, h, SRCCOPY
StretchBlt Me.hdc, w, h, w, -h, pic1.hdc, 0, 0, w, h, SRCCOPY
StretchBlt Me.hdc, w, 3 * h, w, -h, pic1.hdc, 0, 0, w, h, SRCCOPY
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值