C#相当于VB6.0的代码

本文关键字:代码 VB6 相当于 | 更新日期: 2023-09-27 18:25:08

Option Explicit  
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long    
Function TimerCreate() As Boolean
    If g_CTimer Is Nothing Then Exit Function
    ' Create the timer
    g_CTimer.TimerID = SetTimer(0&, 0&, g_CTimer.Interval, AddressOf TimerProc)
    If g_CTimer.TimerID Then
        TimerCreate = True
    Else
        TimerCreate = False
        g_CTimer.TimerID = 0
     End If   
End Function  
Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
    On Error Resume Next
    If g_CTimer Is Nothing Then Exit Sub
    g_CTimer.ThatTime
End Sub

C#相当于VB6.0的代码

对于计时器,您可能需要:

System.Threading.Timer myTimer =
    new System.Threading.Timer(TimerProc, null, g_CTimer.Interval, g_CTimer.Interval);

请参阅System.Threading.Timer.

如果你真的需要使用多媒体定时器(我不推荐),我建议你阅读Windows定时器,并查看pinvoke.net以获取托管原型。例如,SetTimer。