'This project needs a ListBox, named List1 and a TextBox, named Text1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F
Private Sub Form_Load()
    'Add some items to the listbox
    With List1
        .AddItem "Computer"
        .AddItem "Screen"
        .AddItem "Modem"
        .AddItem "Printer"
        .AddItem "Scanner"
        .AddItem "Sound Blaster"
        .AddItem "Keyboard"
        .AddItem "CD-Rom"
        .AddItem "Mouse"
    End With
End Sub
Private Sub Text1_Change()
    'Retrieve the item's listindex
    List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub
这个例子,可以使listbox根据在文本框里输入字符定位到相应字母开头的条目

解决方案 »

  1.   

    Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Sub ReleaseCapture Lib "User32" ()
    Const WM_NCLBUTTONDOWN = &HA1
    Const HTCAPTION = 2
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim lngReturnValue As Long
        If Button = 1 Then
            'Release capture
            Call ReleaseCapture
            'Send a 'left mouse button down on caption'-message to our form
            lngReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
        End If
    End Sub
    Private Sub Form_Paint()
        Me.Print "Click on the form, hold the mouse button and drag it"
    End Sub
      

  2.   

    keybd_event VB声明 
    Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) 
    说明 
    这个函数模拟了键盘行动 
    参数表 
    参数 类型及说明 
    bVk Byte,欲模拟的虚拟键码 
    bScan Byte,键的OEM扫描码 
    dwFlags Long,零;或设为下述两个标志之一 
    KEYEVENTF_EXTENDEDKEY 指出是一个扩展键,而且在前面冠以0xE0代码 
    KEYEVENTF_KEYUP 模拟松开一个键 
    dwExtraInfo Long,通常不用的一个值。api函数GetMessageExtraInfo可取得这个值。允许使用的值取决于特定的驱动程序 
    注解 
    这个函数支持屏幕捕获(截图)。在win95和nt4.0下这个函数的行为不同 
      

  3.   

    对不起,我比较苯,还是没有试成功。
    我要做的是这样的过程:
    在一个已运行的第三方程序(如 test.exe )的文本框中输入一句话(如 "send the sentence" )
    现在的问题是:
    1、怎样得到这个程序的hWnd;
    2、怎样发送这句话。以前是用sendkeys的,但不稳定。
    还请各位大侠帮忙,贴一下解决方案。谢谢。