类和模块中不允许引用timer控件,怎么办?

doglu 2003-08-19 04:33:00
类和模块中不允许引用timer控件,而在编程中又必须使用timer控件,怎么办?有其他办法把timer控件加进来吗?
...全文
64 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhiqiuchen 2003-08-20
  • 打赏
  • 举报
回复
在模块中编写过程,然后在主窗体中使用时间控件的中断呼叫这些过程。
还想懒够 2003-08-20
  • 打赏
  • 举报
回复
有一个sleep的API函数,可以实现时钟的作用
Alicky 2003-08-20
  • 打赏
  • 举报
回复
最简单就是你自己加在窗口中,用form1.timer1....
zyl910 2003-08-20
  • 打赏
  • 举报
回复
'In a module
Public Const DT_CENTER = &H1
Public Const DT_WORDBREAK = &H10
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub
'In a form
Private Sub Form_Load()
Me.Caption = "Key Spy"
'Create an API-timer
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
zyl910 2003-08-20
  • 打赏
  • 举报
回复
VB的Timer控件就是用SetTimer做的

handwolf 2003-08-20
  • 打赏
  • 举报
回复

你可以在你的类模块中声明一个事件(event1)
然后可以像(龙堂)那样建一个带有timer的窗体(form1)
1,在timer事件中添加处理代码(触发你在类模块中声明的事件event1)

2,在你的类模块中new一个form1的对象frm1,添加函数激活frm1的timer

3,在类模块中处理event1事件(比如关闭frm1或timer)


zhangjsl 2003-08-20
  • 打赏
  • 举报
回复
在类中用withevent time1 as timer
就可以操作time1了吧,
doglu 2003-08-19
  • 打赏
  • 举报
回复
to 龙堂:
我的意思是:叫timer事件发生在模块或者类中而不是在窗体中。
doglu 2003-08-19
  • 打赏
  • 举报
回复
to 金:
我对你给出的SetTimer和KillTimer不熟悉,如果他们只有延时的功能,那将很抱歉,你的善举仍帮不了我。因为手机短信的群发不但但需要延迟那么简单。
danielinbiti 2003-08-19
  • 打赏
  • 举报
回复
Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
DragonSchool 2003-08-19
  • 打赏
  • 举报
回复
'在窗体
Private Sub Command1_Click()
testTimer Timer1
End Sub

Private Sub Timer1_Timer()
Me.Caption = Now
End Sub



‘在模块
Sub testTimer(tmr As Timer)
tmr.Enabled = True
tmr.Interval = 1000
End Sub
doglu 2003-08-19
  • 打赏
  • 举报
回复
以上代码时在类中加的
doglu 2003-08-19
  • 打赏
  • 举报
回复
刚才试过了
Private msFlex As Timer
Public Sub LoadControl(ControlObject As Object)
Set msFlex = ControlObject
msFlex.Interval = 1000
msFlex.Enabled = True

End Sub
但这还不够,Timer1_Timer的功能.大峡们,帮帮我吧,我刚参加工作,而且这是老板给我的第一个任务,完不成就惨了,拜托了
wumy_ld 2003-08-19
  • 打赏
  • 举报
回复
与一个窗体建立联系,在窗体上放Timer控件,当事件触发时,在执行类和模块中的代码

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧