Firstly, I would not really bother using a timer definition by decaring the API. You can add a timer to your code by dragging it onto the form from the ToolBox. Then I suggest you look at the help for this.
But to answer your question it's 'Me.Handle' but you need to change the declaration of the SetTimer function window handle to to 'System.IntPtr' not Long. This is a system dependent integer value Type.
Regards - OHM#
(E-Mail Removed)
"Tanzim Saqib" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
I've been trying to learn VB.NET. I know VB6. I can not convert the following VB6 code segment to VB.NET
In VB 6:
' In a module starts here:
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Cnt As Long, sSave As String, sOld As String, Ret As String
Public Function GetPressedKey() As String
For Cnt = 32 To 128
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Public 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
' ends here
' In the code window of form1 starts here:
Private Sub Form_Load()
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Unload(Cancel As Integer)
KillTimer Me.hwnd, 0
MsgBox sSave
End Sub
' ends here
I wrote in VB.NET:
' In a form
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
Dim Cnt As Long, sSave As String, sOld As String, Ret As String
Function GetPressedKey() As String
For Cnt = 32 To 128
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
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' following 2 lines produces this error:
' D:\WindowsApplication1\Form1.vb(69): 'hwnd' is not a member of 'WindowsApplication1.Form1'
SetTimer(Me.hwnd, 0, 1, AddressOf TimerProc)
KillTimer(Me.hwnd, 0)
MsgBox(sSave)
End Sub
What can I write instead of Me.hwnd ??
Thanks in advance!
Tanzim Saqib
Problemsetter, ACM Valladolid Online Judge, Spain.
Website:
http://tanzim.tk
This posting is provided "AS IS" with no warranties.