| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4111 人关注过本帖
标题:新手请教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
快速回复:新手请教sendmessage的用法
数据加载中...
 
   



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

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