我想实现软件“不知不觉背单词”的功能:
(1)每隔一段时间显示不同的单词。(从文件中读取一行内容并显示到主窗口中)
(2)由于每一行(如:abuse[T]2'bju:z, 2'bju:s[M]n. 冷落;虐待;滥用)都是有英文单词、音标,中文意思三部分组成。如何正确显示音标(从文件中读取出来的会显示乱码,有音标文件),并且先显示英文单词、音标,再显示“中文意思”。
尤其是第一个问题,我想用FSO实现。
Function GetWord() as string
dim fso as object
dim f as textstream
.....
if f.atendofstream <>true then
GetWord=f.skipline
end if
....
end Function
.....
Private Sub Form_Load()
timer1.interval=5000 '每隔5秒显示一行内容。
End Sub
Private Sub Timer1_Timer()
FrmMain.Label1.Caption=GetWord
End Sub
以上是对第一个问题的大体思路,但如何实现函数GetWord()每隔5秒钟从文件中读取一行内容赋给FrmMain.Label1.Caption?
还有第二个问题的音标显示问题!
(1)每隔一段时间显示不同的单词。(从文件中读取一行内容并显示到主窗口中)
(2)由于每一行(如:abuse[T]2'bju:z, 2'bju:s[M]n. 冷落;虐待;滥用)都是有英文单词、音标,中文意思三部分组成。如何正确显示音标(从文件中读取出来的会显示乱码,有音标文件),并且先显示英文单词、音标,再显示“中文意思”。
尤其是第一个问题,我想用FSO实现。
Function GetWord() as string
dim fso as object
dim f as textstream
.....
if f.atendofstream <>true then
GetWord=f.skipline
end if
....
end Function
.....
Private Sub Form_Load()
timer1.interval=5000 '每隔5秒显示一行内容。
End Sub
Private Sub Timer1_Timer()
FrmMain.Label1.Caption=GetWord
End Sub
以上是对第一个问题的大体思路,但如何实现函数GetWord()每隔5秒钟从文件中读取一行内容赋给FrmMain.Label1.Caption?
还有第二个问题的音标显示问题!
不应该每次从文件中读取内容,定义一个数组,Form_Load时将所有内容读入内存,并按标志符拆分到数组的每个元素中。(2)音标显示:用标签控件确实无法显示正确。对此没有研究
(ByVal lpFileName As String) As LongPrivate Declare Function RemoveFontResource Lib "gdi32" Alias "RemoveFontResourceA" _
(ByVal lpFileName As String) As Long
Dim lResult As LongPrivate Sub Command1_Click()
'增加字体:
lResult = AddFontResource(App.Path & "\Fonts\Ksphonet.ttf")
If lResult <> 0 Then Text1.FontName = "Kingsoft Phonetic"
End SubPrivate Sub Command2_Click()
'删除字体:
If lResult <> 0 Then
Call RemoveFontResource(App.Path & "\Fonts\Ksphonet.ttf")
lResult = 0
End If
End Sub
1.你的Label(或者其它控件)的字体属性设置为了音标字体吗?
2.你的音标和音标字体文件是一致的吗?
3.你的字体文件注册成功了吗?'***********************************************************
'*希望能够对你有所帮助!
'***********************************************************
'********************************************
'对不起,放一点广告,对您带来的不便敬请原谅!
广告:我的第一个Visual Basic 6.0作品,欢迎大家试用,注册用户得到全部源代码。一、EasyDialog能够做什么?
(为了增强Windows通用打开/保存对话框,能够快速的打开经常访问的文件夹或者文件)
一、快速地在通用打开/保存对话框中打开你经常访问的文件夹/文件。
二、快速地在Windows Explorer中打开经常访问的文件夹/文件。
三、快速地在IE浏览器打开你经常访问的网站。
四、快速地给你的朋友发Email
五、能够使您方便地按照逻辑分类来组织和管理您的文件夹/文件,您经常访问的网址,您的Email地址。'********************************************
'*下载EasyDialog:
http://www.softboyzhou.com/download/EasyDialog.asp
'***************
'*购买EasyDialog:
http://www.softreg.com.cn/shareware_view.asp?id=/7148D197-1C1D-4E84-B92A-EE2CC07D27C0/
'***************
'*给我写信:有什么问题请来信。
[email protected]
金山词霸的音标显示正常是因为每次软件启动时都自动注册字体。
当然可以拷贝字体文件到windows\fonts目录下,这样就不需要每次注册了。
注册字体的方法:Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long
说明
在Windows系统中添加一种字体资源。添加完毕后,该字体即可由任何Windows应用程序调用
返回值
Long,添加的字体数量,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpFileName String,字体资源文件的文件名。可以是.FON, .FNT, .TTF 或 .FOT文件
注解
添加了一种资源后必须调用下述API函数:
di% = SendMessageBynum(HWND_BROADCAST, WM_FONTCHANGE, x, y)
其中,HWND_BROADCAST、WM_FONTCHANGE使用来自API32.TXT文件的值。这样便可告诉所有Windows应用程序字体列表已发生了变化
示例
Call AddFontResource("myfont.ttf")
Call SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
您所谓的乱码无非指的是E5bAndEn之类的吧?其实E对应“呃”,就是反着写的“e”,5对应“'”就是高音,等等。而大部分字体对于这些字符都是默认的。但大多数音标文件也并不能够正常现实汉字。下面是几年前写的一段音标控件代码。
当然您复制过去是没有用的,因为需要很多音标的小图片
Public Sub inText(inText As String)
If Len(inText) = 0 Then UserControl.Cls: UserControl.Width = 75: Exit SubDim setn As Integer '定义字符数
Dim strtemp As String '字符临时变量
Dim pW As Integer '字符位置
pW = 0
strtemp = inText
UserControl.Cls
For setn = 1 To Len(strtemp)
If Mid(strtemp, setn, 1) = "w" Then
UserControl.Width = pW + w.Width
UserControl.PaintPicture w.Picture, pW, 0, w.Width, w.Height, 0, 0, w.Width, w.Height, SRCAND
pW = pW + w.Width
ElseIf Mid(strtemp, setn, 1) = "e" Then
UserControl.Width = pW + e.Width
UserControl.PaintPicture e.Picture, pW, 0, e.Width, e.Height, 0, 0, e.Width, e.Height, SRCAND
pW = pW + e.Width
ElseIf Mid(strtemp, setn, 1) = "r" Then
UserControl.Width = pW + r.Width
UserControl.PaintPicture r.Picture, pW, 0, r.Width, r.Height, 0, 0, r.Width, r.Height, SRCAND
pW = pW + r.Width
ElseIf Mid(strtemp, setn, 1) = "t" Then
UserControl.Width = pW + t.Width
UserControl.PaintPicture t.Picture, pW, 0, t.Width, t.Height, 0, 0, t.Width, t.Height, SRCAND
pW = pW + t.Width
ElseIf Mid(strtemp, setn, 1) = "u" Then
UserControl.Width = pW + u.Width
UserControl.PaintPicture u.Picture, pW, 0, u.Width, u.Height, 0, 0, u.Width, u.Height, SRCAND
pW = pW + u.Width
ElseIf Mid(strtemp, setn, 1) = "i" Then
UserControl.Width = pW + i.Width
UserControl.PaintPicture i.Picture, pW, 0, i.Width, i.Height, 0, 0, i.Width, i.Height, SRCAND
pW = pW + i.Width
ElseIf Mid(strtemp, setn, 1) = "p" Then
UserControl.Width = pW + p.Width
UserControl.PaintPicture p.Picture, pW, 0, p.Width, p.Height, 0, 0, p.Width, p.Height, SRCAND
pW = pW + p.Width
ElseIf Mid(strtemp, setn, 1) = "s" Then
UserControl.Width = pW + s.Width
UserControl.PaintPicture s.Picture, pW, 0, s.Width, s.Height, 0, 0, s.Width, s.Height, SRCAND
pW = pW + s.Width
ElseIf Mid(strtemp, setn, 1) = "d" Then
UserControl.Width = pW + d.Width
UserControl.PaintPicture d.Picture, pW, 0, d.Width, d.Height, 0, 0, d.Width, d.Height, SRCAND
pW = pW + d.Width
ElseIf Mid(strtemp, setn, 1) = "f" Then
UserControl.Width = pW + f.Width
UserControl.PaintPicture f.Picture, pW, 0, f.Width, f.Height, 0, 0, f.Width, f.Height, SRCAND
pW = pW + f.Width
ElseIf Mid(strtemp, setn, 1) = "g" Then
UserControl.Width = pW + g.Width
UserControl.PaintPicture g.Picture, pW, 0, g.Width, g.Height, 0, 0, g.Width, g.Height, SRCAND
pW = pW + g.Width
ElseIf Mid(strtemp, setn, 1) = "h" Then
UserControl.Width = pW + h.Width
UserControl.PaintPicture h.Picture, pW, 0, h.Width, h.Height, 0, 0, h.Width, h.Height, SRCAND
pW = pW + h.Width
ElseIf Mid(strtemp, setn, 1) = "j" Then
UserControl.Width = pW + j.Width
UserControl.PaintPicture j.Picture, pW, 0, j.Width, j.Height, 0, 0, j.Width, j.Height, SRCAND
pW = pW + j.Width
ElseIf Mid(strtemp, setn, 1) = "k" Then
UserControl.Width = pW + k.Width
UserControl.PaintPicture k.Picture, pW, 0, k.Width, k.Height, 0, 0, k.Width, k.Height, SRCAND
pW = pW + k.Width
ElseIf Mid(strtemp, setn, 1) = "l" Then
UserControl.Width = pW + l.Width
UserControl.PaintPicture l.Picture, pW, 0, l.Width, l.Height, 0, 0, l.Width, l.Height, SRCAND
pW = pW + l.Width
ElseIf Mid(strtemp, setn, 1) = "z" Then
UserControl.Width = pW + z.Width
UserControl.PaintPicture z.Picture, pW, 0, z.Width, z.Height, 0, 0, z.Width, z.Height, SRCAND
pW = pW + z.Width
ElseIf Mid(strtemp, setn, 1) = "v" Then
UserControl.Width = pW + v.Width
UserControl.PaintPicture v.Picture, pW, 0, v.Width, v.Height, 0, 0, v.Width, v.Height, SRCAND
pW = pW + v.Width
ElseIf Mid(strtemp, setn, 1) = "b" Then
UserControl.Width = pW + b.Width
UserControl.PaintPicture b.Picture, pW, 0, b.Width, b.Height, 0, 0, b.Width, b.Height, SRCAND
pW = pW + b.Width
ElseIf Mid(strtemp, setn, 1) = "n" Then
UserControl.Width = pW + n.Width
UserControl.PaintPicture n.Picture, pW, 0, n.Width, n.Height, 0, 0, n.Width, n.Height, SRCAND
pW = pW + n.Width
ElseIf Mid(strtemp, setn, 1) = "m" Then
UserControl.Width = pW + m.Width
UserControl.PaintPicture m.Picture, pW, 0, m.Width, m.Height, 0, 0, m.Width, m.Height, SRCAND
pW = pW + m.Width
ElseIf Mid(strtemp, setn, 1) = "Q" Then
UserControl.PaintPicture qq.Picture, pW, 0, qq.Width, qq.Height, 0, 0, qq.Width, qq.Height, SRCAND
pW = pW + qq.Width
ElseIf Mid(strtemp, setn, 1) = "W" Then
UserControl.Width = pW + ww.Width
UserControl.PaintPicture ww.Picture, pW, 0, ww.Width, ww.Height, 0, 0, ww.Width, ww.Height, SRCAND
pW = pW + ww.Width
ElseIf Mid(strtemp, setn, 1) = "E" Then
UserControl.Width = pW + ee.Width
UserControl.PaintPicture ee.Picture, pW, 0, ee.Width, ee.Height, 0, 0, ee.Width, ee.Height, SRCAND
pW = pW + ee.Width
ElseIf Mid(strtemp, setn, 1) = "R" Then
UserControl.Width = pW + rr.Width
UserControl.PaintPicture rr.Picture, pW, 0, rr.Width, rr.Height, 0, 0, rr.Width, rr.Height, SRCAND
pW = pW + rr.Width
ElseIf Mid(strtemp, setn, 1) = "T" Then
UserControl.Width = pW + tt.Width
UserControl.PaintPicture tt.Picture, pW, 0, tt.Width, tt.Height, 0, 0, tt.Width, tt.Height, SRCAND
pW = pW + tt.Width
ElseIf Mid(strtemp, setn, 1) = "A" Then
UserControl.Width = pW + aa.Width
UserControl.PaintPicture aa.Picture, pW, 0, aa.Width, aa.Height, 0, 0, aa.Width, aa.Height, SRCAND
pW = pW + aa.Width
ElseIf Mid(strtemp, setn, 1) = "F" Then
UserControl.Width = pW + ff.Width
UserControl.PaintPicture ff.Picture, pW, 0, ff.Width, ff.Height, 0, 0, ff.Width, ff.Height, SRCAND
pW = pW + ff.Width
ElseIf Mid(strtemp, setn, 1) = "Z" Then
UserControl.Width = pW + zz.Width
UserControl.PaintPicture zz.Picture, pW, 0, zz.Width, zz.Height, 0, 0, zz.Width, zz.Height, SRCAND
pW = pW + zz.Width
ElseIf Mid(strtemp, setn, 1) = "C" Then
UserControl.Width = pW + cc.Width
UserControl.PaintPicture cc.Picture, pW, 0, cc.Width, cc.Height, 0, 0, cc.Width, cc.Height, SRCAND
pW = pW + cc.Width
ElseIf Mid(strtemp, setn, 1) = "V" Then
UserControl.Width = pW + vv.Width
UserControl.PaintPicture vv.Picture, pW, 0, vv.Width, vv.Height, 0, 0, vv.Width, vv.Height, SRCAND
pW = pW + vv.Width
ElseIf Mid(strtemp, setn, 1) = "B" Then
UserControl.Width = pW + bb.Width
UserControl.PaintPicture bb.Picture, pW, 0, bb.Width, bb.Height, 0, 0, bb.Width, bb.Height, SRCAND
pW = pW + bb.Width
ElseIf Mid(strtemp, setn, 1) = "N" Then
UserControl.Width = pW + nn.Width
UserControl.PaintPicture nn.Picture, pW, 0, nn.Width, nn.Height, 0, 0, nn.Width, nn.Height, SRCAND
pW = pW + nn.Width
ElseIf Mid(strtemp, setn, 1) = "5" Then
UserControl.Width = pW + p5.Width
UserControl.PaintPicture p5.Picture, pW, 0, p5.Width, p5.Height, 0, 0, p5.Width, p5.Height, SRCAND
pW = pW + p5.Width
ElseIf Mid(strtemp, setn, 1) = "7" Then
UserControl.Width = pW + p7.Width
UserControl.PaintPicture p7.Picture, pW, 0, p7.Width, p7.Height, 0, 0, p7.Width, p7.Height, SRCAND
pW = pW + p7.Width
ElseIf Mid(strtemp, setn, 1) = "9" Then
UserControl.Width = pW + p9.Width
UserControl.PaintPicture p9.Picture, pW, 0, p9.Width, p9.Height, 0, 0, p9.Width, p9.Height, SRCAND
pW = pW + p9.Width
ElseIf Mid(strtemp, setn, 1) = "," Then
UserControl.Width = pW + Douhao.Width
UserControl.PaintPicture Douhao.Picture, pW, 0, Douhao.Width, Douhao.Height, 0, 0, Douhao.Width, Douhao.Height, SRCAND
pW = pW + Douhao.Width
ElseIf Mid(strtemp, setn, 1) = ":" Then
UserControl.Width = pW + Maohao.Width
UserControl.PaintPicture Maohao.Picture, pW, 0, Maohao.Width, Maohao.Height, 0, 0, Maohao.Width, Maohao.Height, SRCAND
pW = pW + Maohao.Width
ElseIf Mid(strtemp, setn, 1) = "(" Then
UserControl.Width = pW + KuoHoaz.Width
UserControl.PaintPicture KuoHoaz.Picture, pW, 0, KuoHoaz.Width, KuoHoaz.Height, 0, 0, KuoHoaz.Width, KuoHoaz.Height, SRCAND
pW = pW + KuoHoaz.Width
ElseIf Mid(strtemp, setn, 1) = ")" Then
UserControl.Width = pW + KuoHoay.Width
UserControl.PaintPicture KuoHoay.Picture, pW, 0, KuoHoay.Width, KuoHoay.Height, 0, 0, KuoHoay.Width, KuoHoay.Height, SRCAND
pW = pW + KuoHoay.Width
ElseIf Mid(strtemp, setn, 1) = "[" Then
UserControl.Width = pW + FKuoHoaz.Width
UserControl.PaintPicture FKuoHoaz.Picture, pW, 0, FKuoHoaz.Width, FKuoHoaz.Height, 0, 0, FKuoHoaz.Width, FKuoHoaz.Height, SRCAND
pW = pW + FKuoHoaz.Width
ElseIf Mid(strtemp, setn, 1) = "]" Then
UserControl.Width = pW + FKuoHoay.Width
UserControl.PaintPicture FKuoHoay.Picture, pW, 0, FKuoHoay.Width, FKuoHoay.Height, 0, 0, FKuoHoay.Width, FKuoHoay.Height, SRCAND
pW = pW + FKuoHoay.Width
ElseIf Mid(strtemp, setn, 1) = "/" Then
UserControl.Width = pW + Xiexian.Width
UserControl.PaintPicture Xiexian.Picture, pW, 0, Xiexian.Width, Xiexian.Height, 0, 0, Xiexian.Width, Xiexian.Height, SRCAND
pW = pW + Xiexian.Width
ElseIf Mid(strtemp, setn, 1) = " " Then
UserControl.Width = pW + placebar.Width
UserControl.PaintPicture placebar.Picture, pW, 0, placebar.Width, placebar.Height, 0, 0, placebar.Width, placebar.Height, SRCAND
pW = pW + placebar.Width
End If
NextEnd Sub