如何在VB6中用API实现文本转换为位图?
我的窗体上加入一个名为pbx的picturebox,两个按钮command1,command2
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type Size
cx As Long
cy As Long
End Type
Private Const TRANSPARENT = 1
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Size) 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 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 BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Private Const DT_BOTTOM = &H8
Private Const DT_CALCRECT = &H400
Private Const DT_CENTER = &H1
Private Const DT_CHARSTREAM = 4 ' Character-stream, PLP
Private Const DT_DISPFILE = 6 ' Display-file
Private Const DT_EXPANDTABS = &H40
Private Const DT_EXTERNALLEADING = &H200
Private Const DT_INTERNAL = &H1000
Private Const DT_LEFT = &H0
Private Const DT_METAFILE = 5 ' Metafile, VDM
Private Const DT_NOCLIP = &H100
Private Const DT_NOPREFIX = &H800
Private Const DT_PLOTTER = 0 ' Vector plotter
Private Const DT_RASCAMERA = 3 ' Raster camera
Private Const DT_RASDISPLAY = 1 ' Raster display
Private Const DT_RASPRINTER = 2 ' Raster printer
Private Const DT_RIGHT = &H2
Private Const DT_SINGLELINE = &H20
Private Const DT_TABSTOP = &H80
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WORDBREAK = &H10
Private Sub Command1_Click()
Dim nResult As Long
Dim szText As String
Dim lpRect As RECT
Dim lpSize As Size
Dim hThisDC As Long
szText = "Hellodflkhqewttttttttt" & Chr(13) & "4wq65756876980436346t1325t"
hThisDC = pbx.hdc
nResult = GetTextExtentPoint32(hThisDC, szText, Len(szText), lpSize)
nResult = SetBkMode(hThisDC, TRANSPARENT)
nReuslt = SetTextColor(hThisDC, &HC00000)
'nResult = TextOut(pbx.hdc, 0, 0, szText, Len(szText))
lpRect.Top = 0
lpRect.Left = 0
lpRect.Bottom = pbx.Width / Screen.TwipsPerPixelX
lpRect.Right = pbx.Height / Screen.TwipsPerPixelY
nResult = DrawText(hThisDC, szText, Len(szText), lpRect, DT_NOCLIP Or DT_WORDBREAK Or DT_LEFT Or DT_TOP)
nResult = BitBlt(pbx.Picture.Handle, 0, 0, pbx.Width, pbx.Height, pbx.hdc, 0, 0, SRCCOPY)
End Sub
Private Sub Command2_Click()
SavePicture pbx.Picture, "D:\Borland\Led\09\my.bmp"
End Sub
Private Sub Form_Load()
pbx.Picture = LoadPicture("D:\Borland\Led\09\AllGrn.bmp")
End Sub
但是无论怎样,也不能将文本转换的位图放入picturebox.picture中,也不能保存。可否给予帮助,谢谢。