麻烦老师,帮忙看看,我对API和GDI不太熟悉,这个代码是自定义窗体的,现在的问题是,标题栏只输入中文没有问题,如果标题栏中文英文和数字混排出现,标题栏的字符串结尾会出现乱码
例如:贵阳(M-21)地块项目 或者 昆明学府路(东段)2011地块项目, 在字符串结尾处就出现各种乱码,除非字符串数量超出RECT区域,经过H40000处理出现省略...才正常。
因为全部代码在这里无法全部上传(点发表,上传报错,无法上传),只能截取存在错误的代码请老师帮忙看看 其他未上传的代码应该没有问题,自定义的窗体都能正常生成和使用
Public Class Class2
........省略代码
Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Integer, ByVal lpStr As String, ByVal nCount As Integer, ByRef lpRect As RECT, ByVal wFormat As Integer) As Integer
Public Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal H As Integer, ByVal W As Integer, ByVal E As Integer, ByVal O As Integer, ByVal W As Integer, ByVal I As Integer, ByVal u As Integer, ByVal S As Integer, ByVal C As Integer, ByVal OP As Integer, ByVal CP As Integer, ByVal Q As Integer, ByVal PAF As Integer, ByVal F As String) As Integer
'写标题
Dim sTitle As String = myform.Text
SetBkMode(hMem, &H1)
Dim hFont As Integer = CreateFont(14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "宋体")
SelectObject(hMem, hFont)
SetTextColor(hMem, &HF8F8FF) 'HFFFFFF
Dim rcWindow1 As New RECT
rcWindow1.Left = 35
rcWindow1.Top = 9
rcWindow1.Right = 900 'rcWindow.Right-200 '-100
rcWindow1.Bottom = 29
DrawText(hMem,sTitle,sTitle.Length*2,rcWindow1,&H0 Or &H4 Or &H20 Or &H40000) 'H20单行定义 H40000截短省略
DeleteObject(hFont)
...........省略代码
Public myf orm As Windows.F orms.F orm
End Class