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

就没有人知道timeSetEvent?该怎么处理

2012-03-13 
就没有人知道timeSetEvent?lTimeIDtimeSetEvent(1000,10,AddressOfTimeProc,1,1)在回调函数中,只要有msgb

就没有人知道timeSetEvent?
lTimeID   =   timeSetEvent(1000,   10,   AddressOf   TimeProc,   1,   1)  
在回调函数中,只要有msgbox   "1 "   之类的语句,在vb环境下可以执行,但是编译成可执行文件就会出现死机,请问是为什么?
问题补充:
Form中的  

Private   Sub   Command2_Click()  
EndCount  
End   Sub  

Private   Sub   Command3_Click()  
EndCount  
End  
End   Sub  

Private   Sub   Form_Load()  
lTimeID   =   timeSetEvent(3000,   80,   AddressOf   TimeProc,   1,   1)  
End   Sub  

模块中的  
Option   Explicit  

Public   lTimeID   As   Long  
Dim   i   As   Integer  

Public   Declare   Function   timeSetEvent   Lib   "winmm.dll "   (ByVal   uDelay   As   Long,   ByVal   uResolution   As   Long,   ByVal   lpFunction   As   Long,   ByVal   dwUser   As   Long,   ByVal   uFlags   As   Long)   As   Long  
Public   Declare   Function   timeKillEvent   Lib   "winmm.dll "   (ByVal   uID   As   Long)   As   Long  

'timeSetEvent的回调函数  
Sub   TimeProc(ByVal   uID   As   Long,   ByVal   uMsg   As   Long,   ByVal   dwUser   As   Long,   ByVal   dw1   As   Long,   ByVal   dw2   As   Long)  

Form1.Text2.Text   =   i  
i   =   i   +   1  
Call   DB  

End   Sub  

Sub   EndCount()  

timeKillEvent   lTimeID  

End   Sub  

Sub   DB()  
Form1.Text2.Text   =   i  
MsgBox   "1 "  
End   Sub  


[解决办法]
IDE下的msgbox与运行时的msgbox工作机制不同,VB为了调试需要,前者弹出时会中断整个线程的所有消息处理进行等待,而运行时则只中断过程执行,线程消息处理仍会继续。
你可有两种选择:
1、不要使用MsgBox或模式窗体中断回调函数;
2、换用SetTimer,印象中它的调函数中可以使用MsgBox

另外,使用API的MessageBox,不知行不行,你可试试。

热点排行