Changeset 679 for trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI
- Timestamp:
- Jan 26, 2009, 1:53:37 AM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
r674 r679 1 1 'Classes/ActiveBasic/Windows/UI/Control.ab 2 2 3 #require <Classes/ActiveBasic/Windows/UI/WindowHandle.ab> 3 4 #require <Classes/ActiveBasic/Windows/UI/EventArgs.ab> 4 5 #require <Classes/ActiveBasic/COM/ComClassBase.ab> -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Timer.ab
r677 r679 1 2 #require <Classes/ActiveBasic/Windows/UI/Control.ab> 1 3 /* 2 4 @brief タイマ … … 10 12 Public 11 13 'Timer クラスの新しいインスタンスを初期化します。 12 Sub Timer() 13 Dim tc As TIMECAPS 14 timeGetDevCaps(tc,SizeOf(TIMECAPS)) 15 If 50 < tc.wPeriodMin Then 16 '今の時代にこんなPCはほとんどないだろうけど念のため 17 This.resolution = tc.wPeriodMin 18 Else 19 'Froms.Timerの精度は55msec前後 20 This.resolution = 50 21 End If 14 Sub Timer(control As Control) 15 If IsNothing(control) Then 16 Throw New System.ArgumentNullException("control") 17 EndIf 18 ctrl = control 22 19 End Sub 23 20 … … 25 22 Sub Enabled(value As Boolean) 26 23 If value Then 27 If This. id=0 Then This.Start()24 If This.handle=0 Then This.Start() 28 25 Else 29 If This. idThen This.Stop()26 If This.handle Then This.Stop() 30 27 End If 31 28 End Sub 32 29 Function Enabled() As Boolean 33 Return This.enabled30 Return handle <> 0 34 31 End Function 35 32 … … 52 49 'オーバーロードされます。 53 50 Sub Dispose() 54 This.Stop()51 killImpl() 55 52 End Sub 56 53 57 54 'タイマを起動します。 58 55 Sub Start() 59 This.id = timeSetEvent(This.interval,This.resolution,AddressOf(Detail.TimerProc_Impl),ObjPtr(This) As ULONG_PTR,TIME_PERIODIC or TIME_CALLBACK_FUNCTION) 60 If This.id Then This.enabled = True Else This.enabled = False 56 If handle = 0 Then 57 handle = AllocObjectHandle(This) 58 If SetTimer(ctrl As HWND, handle, interval, AddressOf(timerProc)) = 0 Then 59 ThrowWithLastError() 60 End If 61 End If 61 62 End Sub 62 63 63 64 'タイマを停止します。 64 65 Sub Stop() 65 timeKillEvent(This.id)66 This.id = 067 This.enabled = False66 If killImpl() = 0 Then 67 ThrowWithLastError() 68 End If 68 69 End Sub 69 70 … … 80 81 End Sub 81 82 82 Protected83 id As ULONG_PTR84 interval As Long85 resolution As DWord86 enabled As Boolean87 tag As Object88 89 83 Public 90 84 Sub AddTick(h As System.EventHandler) … … 100 94 End If 101 95 End Sub 96 Private 97 Static Sub timerProc(hwnd As HWND, msg As DWord, id As ULONG_PTR, time As DWord) 98 Dim timer = GetObjectFromHandle(id) As Timer 99 timer.OnTick(Nothing) 100 End Sub 101 102 Function killImpl() As Boolean 103 If handle <> 0 Then 104 killImpl = KillTimer(ctrl As HWND, handle) <> 0 105 ReleaseObjectHandle(handle) 106 handle = 0 107 End If 108 End Function 102 109 103 110 Tick As System.EventHandler 111 ctrl As Control 112 handle As LONG_PTR 'タイマ実行中のGC回避およびタイマIDとして使用 113 interval As DWord 104 114 End Class 105 106 107 Namespace Detail108 Class Timer_Impl109 Inherits Timer110 111 Public112 Sub OnTick()113 Super.OnTick(Nothing)114 End Sub115 End Class116 117 Sub TimerProc_Impl(uID As DWord, uMsg As DWord, dwUser As DWORD_PTR, dw1 As DWORD_PTR, dw2 As DWORD_PTR)118 Dim timer As Timer_Impl119 timer = dwUser As Timer_Impl120 timer.OnTick()121 End Sub122 123 End Namespace124 115 125 116 End Namespace 'UI
Note:
See TracChangeset
for help on using the changeset viewer.