求助:关于向其它程序窗口的按钮传送鼠标单击,不能激活其鼠标单击事件的问题?
我弄了两天,已经把代码写出来了.先找到指定窗口(我公司专用的生产数据统计软件)的句柄,然后找到按钮的句柄,之后向发送单击,但那个按钮事件没有响应.后来我把代码用来操作IE的属性对话窗口(Internet 属性/选项),IE的属性窗口的按钮能够响应代码传送过来的鼠标单击,也就是说代码是正确的.
是不是我公司的统计软件中的按钮比较特别,请问还有什么办法能够向按钮传送鼠标单击?(我已经获得了这个按钮的句柄,为什么传送不了鼠标单击事件?而IE的又可以?)
[解决办法]
如果,你确定确实是按钮的话,用sendmessage发送BM_CLICK消息即可,具体代码用google搜之
[解决办法]
正好昨天写了一个相关的程序。分享给大家看看
開啟Notes自動輸入密碼
Declare Function GetClassNameA Lib "user32 " (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function FindWindowA& Lib "user32 " (ByVal lpClassName$, ByVal lpWindowName$)
Declare Function SetActiveWindow Lib "user32 " (ByVal hwnd As Long) As Long
Declare Function GetWindow Lib "user32 " (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowTextA Lib "user32 " (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendString Lib "user32 " Alias "SendMessageA " (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As String
Declare Function SendCommand Lib "user32 " Alias "SendMessageA " (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As String
Const WM_SETTEXT = &HC
Const BM_CLICK = &HF5
Const GW_CHILD = 5
Const GW_HWNDNEXT = 2
Function GetClassNameStr(hwnd As Long) As String
Dim TempStr As String
Dim Rc As Long
TempStr = Space(260)
Rc = GetClassNameA(hwnd, TempStr, Len(TempStr))
GetClassNameStr = StrConv(LeftB$(StrConv(TempStr, vbFromUnicode), Rc), vbUnicode)
End Function
Function GetWndText(hwnd As Long) As String
Dim K As Long
Dim sName As String
sName = Space$(128)
K = GetWindowTextA(hwnd, sName, Len(sName))
GetWndText = IIf(K > 0, Left$(sName, K), "未知 ")
End Function
Private Sub Form_Load()
Me.Hide
Dim hwnd As Long
Dim CName As String
Call Shell( "d:\Lotus\Notes\notes.exe ", 1)
Do While True
hwnd = FindWindowA( "#32770 ", "輸入密碼 ")
If hwnd <> 0 Then SetActiveWindow hwnd: Exit Do
Loop
DoEvents
hwnd = GetWindow(hwnd, GW_CHILD)
If hwnd = 0 Then Exit Sub
Do While hwnd > 0
Select Case GetClassNameStr(hwnd)
Case "IRIS.password "
SendString hwnd, WM_SETTEXT, 0&, "1234 "
Case "Button "
'無焦點需發兩次
If InStr(GetWndText(hwnd), "確定 ") Then SendCommand hwnd, BM_CLICK, 0, 0
End Select
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End
End Sub
[解决办法]
你用PostMessage试一下
[解决办法]
同楼上