整了好多天的双击listbox的某一项终于整出来了,在这里保存一下
模块:
Imports System.Runtime.InteropServices
Imports System
Imports System.IO
Imports System.Text
Imports System.Math
Module Module1
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Integer
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Integer) As Integer
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Public Const WM_USER As Integer = &H400
Public Const LB_GETCOUNT As Integer = (WM_USER + 12)
Public Const LB_SETCURSEL As Integer = &H186
Public Const LB_GETCURSEL As Integer = &H188
Public Const WM_LBUTTONDOWN As Integer = &H201
Public Const WM_LBUTTONUP As Integer = &H202
Public Const WM_LBUTTONDBLCLK As Integer = &H203
Public WinHandle As Integer
Public PanelHandle As Integer
Public LVHandle As Integer
Public LVHandle1 As Integer
End Module
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
WinHandle = FindWindow(vbNullString, "金未来智能标记系统2010 - 中正金码 标记专家 -[脱机]")
SetForegroundWindow(WHandle)
'MessageBox.Show(WinHandle)
If WinHandle <> 0 Then
PanelHandle = FindWindowEx(WinHandle, vbNullString, "TPanel", vbNullString)
PanelHandle = FindWindowEx(WinHandle, PanelHandle, "TPanel", vbNullString)
' MessageBox.Show(PanelHandle)
If PanelHandle <> 0 Then
LVHandle1 = FindWindowEx(PanelHandle, 0, "TListBox", vbNullString)
'MessageBox.Show(LVHandle1)
If LVHandle1 <> 0 Then
SendMessage(LVHandle1, LB_SETCURSEL, 3, 0)
Dim ID As Integer = SendMessage(LVHandle1, LB_GETCURSEL, 0, 0)
Dim x As Integer = 2
Dim y As Integer = ID * 20
SendMessage(LVHandle1, WM_LBUTTONDBLCLK, 1, (y << 16) + x)
End If
End If
End If
End Sub