错误获取表格处理程序(Vb.net)

| 我有当前代码:
Public Declare Function FindWindow Lib \"user32.dll\" Alias \"FindWindowA\" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

<DllImport(\"user32.dll\", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As HandleRef, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
End Function

Declare Auto Function SendMessage Lib \"user32.dll\" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

Public Function WindowHandle(ByVal sTitle As String) As Long
    WindowHandle = FindWindow(vbNullString, sTitle)
End Function

Dim CurrentProcess As Process
Dim CurrentHandle As IntPtr

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    SendMessage(CurrentHandle, 256, Keys.A, 0)
    SendMessage(CurrentHandle, 257, Keys.A, 65539)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        CurrentProcess = Process.GetProcessesByName(ListBox1.SelectedItem.ToString.Remove(0, ListBox1.SelectedItem.ToString.IndexOf(\"{\") + 1).Replace(\"}\", \"\"))(0)
        CurrentHandle = New IntPtr(WindowHandle(CurrentProcess.MainWindowTitle))
        Timer1.Start()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub
如果您查看一下按钮子,则每次它运行时,都会出现“算术溢出错误!”错误。 怎么了这应该工作...对吗? 抱歉,这有点含糊,但据我所知。     
已邀请:
您的声明声明是正确的,但调用它们的方式却不正确。 VB.NET允许的松散类型使您陷入无法诊断的麻烦。解决的办法是让编译器告诉您您做错了。将其放在源代码文件的顶部:
 Option Strict On
    

要回复问题请先登录注册