标题:新手请教sendmessage的用法
只看楼主
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 
回复:(b13690976754)新手请教sendmessage的用法
经过研究我已经掌握了 怎么获得窗口的句柄(师傅功劳最大)但是我向窗体发送信息时 遇到这个错误。。


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-04-20 17:09
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
得分:0 
API函数声明或是调用参数错。

VB QQ群:47715789
2007-04-20 17:42
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)

Private Const WM_KEYDOWN = &H100
Private Sub Command1_Click()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
Dim hwnd As Long '
hwnd = FindWindow(vbNullString, "Crazy Arcade")
If hwnd = 0 Then
Label1.Caption = "未运行"
Else
Label1.Caption = "已运行"
SendMessage findhwnd, WM_KEYDOWN, 65, 1& 这个出错了。如果我要向 泡泡堂 发送一个字符怎么改? (比如我发送 : 你好 )怎么样才能不出现DLL错误?
End If
End Sub


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-04-20 17:54
redice
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:902
专家分:0
注 册:2006-12-11
得分:0 
回复:(b13690976754)师傅~Private Const WM_KEYDOW...
Private Const WM_KEYDOWN = &H100 "这里声明一个常量,指按键被按下信息,它的值为&H100 ,当然你可以直接用&H100 ,这样做目的是便于记忆
Private Sub Command1_Click()
Dim findhwnd As Long
findhwnd = FindWindow(vbNullString, "消息接收窗体")
If findhwnd = 0 Then '这里将原来的VbNullString改为0。当findhwnd等于零,说明当前的窗口中没有一个名为“消息接收窗体”的窗体,也就是说接受消息窗口没有打开
MsgBox "接受消息窗体没有运行", 0, "报告"
Exit Sub
End If
SendMessage findhwnd, WM_KEYDOWN, 65, 0& ’这是发送消息到上面获取的句柄 其中findhwnd是上面获取的句柄,WM_CLOSE是消息内容说明发送的是按键消息,65是附加参数(即A键)
End Sub

鲲鹏数据 - 专业Web数据采集服务提供者
http://www.
2007-04-20 17:55
redice
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:902
专家分:0
注 册:2006-12-11
得分:0 
回复:(b13690976754) Private Declare Function Fi...
真不好意思 我写错了一点
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) as long

SendMessage findhwnd, WM_KEYDOWN, 65, 0


鲲鹏数据 - 专业Web数据采集服务提供者
http://www.
2007-04-20 17:58
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 
以下是引用redice在2007-4-20 17:58:30的发言:
真不好意思 我写错了一点
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) as long

SendMessage findhwnd, WM_KEYDOWN, 65, 0 & (你又少写了个)

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

Private Sub Command1_Click()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
Dim hwnd As Long '
hwnd = FindWindow(vbNullString, "Crazy Arcade")
If hwnd = 0 Then
Label1.Caption = "未运行"
Else
Label1.Caption = "已运行"
SendMessage findhwnd, wm_keydown, 65, 0& (虽然不会出现DLL错误,但不会输入A。。????)
End If
End Sub


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-04-20 18:04
偶是天才
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2007-4-20
得分:0 

乱蓬蓬的api

2007-04-20 18:06
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 
师傅不在吗?

If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-04-20 18:30
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 

师傅这个是改你编的程序,发现一个问题,这个程序只对你编的另一个窗体有效果,对其他任何一个活动窗体不起作用。。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long

Private Const WM_KEYDOWN = &H100
Private Sub Command1_Click()
Timer1.Interval = 500
End Sub

Private Sub Timer1_Timer()
Dim hwnd As Long '
hwnd = FindWindow(vbNullString, "Crazy Arcade")
If hwnd = 0 Then
Label1.Caption = "未运行"
Else
Label1.Caption = "已运行"
SendMessage findhwnd, wm_keydown, 65, 0&
End If
End Sub

[此贴子已经被作者于2007-4-20 18:55:26编辑过]


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-04-20 18:53
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 

Private Const WM_KEYDOWN = &H100好象用的不对吧?
不然怎么不可以呢???


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-04-20 18:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-132960-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.340942 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved