hWndX =
下行加个debug.print hWndX '看看是否为0
另外应该还少一个api函数FindWindowEx
如果只用窗体一个函数就够了,如果还要窗体下的一个控件那还得需要一个api函数,spy++是看控件类型的,就一窗体根本用不了spy++
参考一下以前我写的(看怎么找控件,用的是sendmessage,你的问题就出在这里):
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
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 Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim s As String, myhwnd As Long
s = Text1
myhwnd = FindWindow(vbNullString, "abc.txt - 记事本")
myhwnd = FindWindowEx(myhwnd, 0&, "Edit", vbNullString) '控件名用spy++查看,这里是Edit,特定的软件控件名都是固定的
If myhwnd = 0 Then
MsgBox "!!"
Exit Sub
End If
SendMessage myhwnd, WM_SETTEXT, 0, ByVal s
End Sub
你的代码是不是这样写的:
wMsg = WM_RBUTTONDOWN'右键按下消息
wParam = 1
lParam =yy*65536+xx
Call PostMessage(hWndX, wMsg, wParam, lParam)’发送消息
Sleep 300
wMsg =WM_RBUTTONUP'右键抬起消息
初学者就折腾这些个啊