首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

急求CreateFont函数构建字体,Textout输出乱码的有关问题

2012-02-13 
急求CreateFont函数构建字体,Textout输出乱码的问题!在设备里输出字符串,用CreateFont构建字体,然后用Text

急求CreateFont函数构建字体,Textout输出乱码的问题!
在设备里输出字符串,用CreateFont构建字体,然后用TextOut输出,结果出现有点象日文的乱码。请各位大哥指教,急等!
代码如下:

Private Sub AddStation(TempDc As Long, TempType As Integer) '输出站点名
 Dim TempConn As ADODB.Connection
 Dim TempRecord As ADODB.Recordset
 Dim TempStream As ADODB.Stream
 Dim TempStationName As String, TempStationLongitude As Single, TempStationLatitude As Single '站点名,经纬度
 Dim P As POINTAPI
 Dim TempCircleX As Single, TempCircleY As Single, TempCircleR As Single '站点名输出位置
 Dim TempResult As Long
 TempResult = SetTextColor(TempDc, vbBlue) '设置字体颜色
 TempResult = SetBkMode(TempDc, Transparent) '设置背景透明
 Dim hSize As Long, vSize As Double '字体大小和纵横比
 Dim hFont As Long '字体变量
 hSize = CLng("16"): vSize = CDbl(Val(Left("100%", Len("100%") - 1)) / 100)
 hFont = CreateFont(CInt(hSize * 22 / 17), CInt(hSize * vSize * 2 / 3), 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, "黑体")
 Call SelectObject(TempDc, hFont)
 Set TempConn = New ADODB.Connection
 TempConn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;UID=" + MapDbUser + ";PWD=" + MapDbPassword + ";Initial Catalog=" + MapDbName + ";network address=" + MapDbSource
 TempConn.ConnectionTimeout = 0
 TempConn.Open
 Set TempRecord = New ADODB.Recordset '建立记录集
 With TempRecord
  .ActiveConnection = TempConn
  .Source = "select * from ZjStationInfor where StationType=" + Trim(Str(TempType))
  .CursorLocation = adUseClient
  .Open
  Do Until .EOF
  TempStationName = Trim(.Fields("StationName"))
  TempStationLongitude = .Fields("Longitude")
  TempStationLatitude = .Fields("Latitude")
  TempCircleX = GetScrX(ShowPicture, TempStationLongitude, CurrentMinX, CurrentMaxX): TempCircleY = GetScrY(ShowPicture, TempStationLatitude, CurrentMinY, CurrentMaxY)
  TextOut TempDc, TempCircleX - 8, TempCircleY - 4, TempStationName, LenB(TempStationName)
  .MoveNext
  Loop
 End With
 DeleteObject hFont
 Set TempRecord = Nothing
 Set TempConn = Nothing
End Sub

程序是调用这个子过程的,其中连接数据库获取站点名称这一部分代码应该没问题。而且不设置字体,直接用Textout输出是正常的。现在想设置字体,结果就输出了一些乱码。不知道是怎么回事。请高手指教。是我的系统问题吗?我用了两台电脑试,都是这个毛病。

[解决办法]
字符集参数不可以乱填,此参数必须选用正确的对应字体的字符集

热点排行