怎么才能在指定窗口(已知句柄)的指定输入框中输入指定的内容,然后再单击“确定”按钮,最好附源码说明!谢谢!

解决方案 »

  1.   

    你还需要输入框和确定按钮的句柄
    1,SetWindowText
    2,SendMessage   消息为WM_COMMAND
      

  2.   

    Option ExplicitPrivate 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 Const WM_SETTEXT = &HC
    Private Declare Function SetFocusApi Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As LongPrivate Sub Command1_Click()
        If Text1.Text = "123" Then
            MsgBox "YES"
        Else
            MsgBox "NO"
        End If
    End SubPrivate Sub Command2_Click()
        SendMessage Text1.hwnd, WM_SETTEXT, 0&, ByVal "123"
        SetFocusApi Command1.hwnd
        SendKeys "{enter}"
    End Sub
    单击按钮,通常是发送下面两条消息:
    Private Const WM_LBUTTONUP = &H202
    Private Const WM_LBUTTONDOWN = &H201
    但是,这两个消息的使用比较麻烦
      

  3.   

    to daviddivad(你真行,居然比我还快! Scorpio) :
    用SendMessage   发送WM_COMMAND消息时,需要用到type nmclick,能提供一下声明吗?
      

  4.   

    twnd = FindWindow("tform2", "身份验证")
    bwnd = FindWindowEx(twnd, ByVal 0&, "tedit", vbNullString)
    Call SendMessage(bwnd, wm_settext, 255, ByVal "12345")
    请问大虾:我以上的语句运行后为什么"tedit"框中却没有任何内容,到底错在哪儿?
      

  5.   

    twnd = FindWindow("tform2", "身份验证")
    bwnd = FindWindowEx(twnd, ByVal 0&, "tedit", vbNullString)
    Call SendMessage(bwnd, wm_settext, 0, ByVal "12345")请问大虾:我以上的语句运行后为什么"tedit"框中却没有任何内容,到底错在哪儿?
      

  6.   

    "tedit"文本框的标题被改为12345,但我想改变的是文本框的文字内容??呜呜!
      

  7.   

    文本框的标题???bwnd = FindWindowEx(twnd, ByVal 0&, "tedit", vbNullString)
    返回值是需要的值吗(用spy查看一下结果)
      

  8.   

    bwnd是正确的值(已经用spy查看结果)
    怎么会事呢?郁闷!
      

  9.   

    函数的用法没有问题,用spy查看一下文本框的类名,贴上来,我继续说
      

  10.   

    参考:
    http://www.china-askpro.com/msg33/qa99.shtml
      

  11.   

    用SetWindowText试试:Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPrivate Sub Command1_Click()
        SetWindowText Text1.Text, "1234abc"
    End Sub
      

  12.   

    to rainstormmaster(rainstormmaster)private type POINT
        x as long 
        y as long 
    end typeprivate type NMHDR
        hwndFrom as long 
        idFrom as long
        code  as long 
    end typeprivate type NMCLICK
        hdr as NMHDR
        dwItemSpec as long
        dwItemData as long
        pt as POINT
        dwHitInfo as long
    end type
      

  13.   

    用SetWindowText也不行,再次郁闷!
      

  14.   

    rainstormmaster(rainstormmaster)大虾呢?
      

  15.   

    SendMessage Text1.hwnd, WM_SETTEXT, 0&, ByVal "test" 
    我在xp下用的,没问题呀。
      

  16.   

    aha99(学习):
    不是Text1.hwnd,而是在其他应用程序中的文本框