谁有外部事件的例子给一个~~~分双手送上,不够绝对可以再加~

wdwd05 2003-10-09 05:10:42
wdwd05@163.com

要自己写的事件

最好是自己写的事件~~~

...全文
78 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdwd05 2003-10-10
  • 打赏
  • 举报
回复
谢谢大家,经过我的努力,大家的帮助,问题终于有眉目了,呵呵~结分~~~
bigpig 2003-10-09
  • 打赏
  • 举报
回复
up
Caney 2003-10-09
  • 打赏
  • 举报
回复
其实VB中的时间就是对WINDOWS消息的映射,所以不妨试试这个方法。
窗体代码:
Option Explicit

Dim ret As Long
Private Sub Command1_Click()
Call SendMessage(Me.Hwnd, WM_MYMSG, 0, 0)
End Sub

Private Sub Form_Load()

preWinProc = GetWindowLong(Me.Hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.Hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
ret& = SetWindowLong(Me.Hwnd, GWL_WNDPROC, preWinProc)
End Sub
模块代码:
Option Explicit
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal Hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const WM_USER = &H400
Public Const GWL_WNDPROC = (-4)
Public Const WM_MYMSG = WM_USER + 100
Public Const WM_RBUTTONDOWN = &H204

Public preWinProc As Long
Public Function WndProc(ByVal Hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_MYMSG Then
MsgBox "Here is my difine message"
Else
WndProc = CallWindowProc(preWinProc, Hwnd, Msg, wParam, lParam)
End If

End Function
通过自定义消息的方法,实现类似的功能!希望对你有帮助
sword281 2003-10-09
  • 打赏
  • 举报
回复
其中updatetime和changetext为自定义事件
online 2003-10-09
  • 打赏
  • 举报
回复
???
射天狼 2003-10-09
  • 打赏
  • 举报
回复
什么意思!?
sword281 2003-10-09
  • 打赏
  • 举报
回复
RaiseEvent Statment Example
The following example uses events to count off seconds during a demonstration of the fastest 100 meter race. The code illustrates all of the event-related methods, properties, and statements, including the RaiseEvent statement.

The class that raises an event is the event source, and the classes that implement the event are the sinks. An event source can have multiple sinks for the events it generates. When the class raises the event, that event is fired on every class that has elected to sink events for that instance of the object.

The example also uses a form (Form1) with a button (Command1), a label (Label1), and two text boxes (Text1 and Text2). When you click the button, the first text box displays "From Now" and the second starts to count seconds. When the full time (9.84 seconds) has elapsed, the first text box displays "Until Now" and the second displays "9.84"

The code for Form1 specifies the initial and terminal states of the form. It also contains the code executed when events are raised.

Option Explicit

Private WithEvents mText As TimerState

Private Sub Command1_Click()
Text1.Text = "From Now"
Text1.Refresh
Text2.Text = "0"
Text2.Refresh
Call mText.TimerTask(9.84)
End Sub

Private Sub Form_Load()
Command1.Caption = "Click to Start Timer"
Text1.Text = ""
Text2.Text = ""
Label1.Caption = "The fastest 100 meters ever run took this long:"
Set mText = New TimerState
End Sub

Private Sub mText_ChangeText()
Text1.Text = "Until Now"
Text2.Text = "9.84"
End Sub

Private Sub mText_UpdateTime(ByVal dblJump As Double)
Text2.Text = Str(Format(dblJump, "0"))
DoEvents
End Sub

The remaining code is in a class module named TimerState. Included among the commands in this module are the Raise Event statements.

Option Explicit
Public Event UpdateTime(ByVal dblJump As Double)
Public Event ChangeText()

Public Sub TimerTask(ByVal Duration As Double)
Dim dblStart As Double
Dim dblSecond As Double
Dim dblSoFar As Double
dblStart = Timer
dblSoFar = dblStart

Do While Timer < dblStart + Duration
If Timer - dblSoFar >= 1 Then
dblSoFar = dblSoFar + 1
RaiseEvent UpdateTime(Timer - dblStart)
End If
Loop

RaiseEvent ChangeText

End Sub

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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