a = FindWindow("#32770", vbNullString)        ’取得父窗口
b = FindWindowEx(a, 0, "ComboBox", vbNullString)’取得子窗口--控件句柄
c = FindWindowEx(a, 0, "Edit", vbNullString)
g = "1111111"           ‘设置要输入的字符
SetWindowText b, g       ’把字符写进去
是不是必须把字符换成另一种形式才能写进去啊?

解决方案 »

  1.   

    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    Private Sub Form_Activate()    Dim MyStr As String
        'Create a buffer
        MyStr = String(100, Chr$(0))
        'Get the windowtext
        GetWindowText Me.hwnd, MyStr, 100
        'strip the rest of buffer
        MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
        'Triple the window's text
        MyStr = MyStr + MyStr + MyStr
        'Set the new window text
        SetWindowText Me.hwnd, MyStr
    End Sub