登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

樱之花

叶散的时候,你明白欢聚;花谢的时候,你明白青春.

 
 
 

日志

 
 
关于我

分类中“我的实验室”是我在日常工作中的一些知识总结,有些写的比较匆忙,可能大家在阅读时会产生困扰,后期有时间我会重新整理编辑,谢谢大家的到访,您们的支持是我前进的动力!

API SendMessage如何发送按钮单击消息  

2009-04-22 13:31:28|  分类: Visual Basic |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

API SendMessage如何发送按钮单击消息,急急急!
请帮我分析一下,为什么会失败!
//我使用了如下API函数
'调用一个窗口的窗口函数,将一条消息发给那个窗口。
除非消息处理完毕,否则该函数不会返回。
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal

hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As

Long
'返回包含了指定点的窗口的句柄。忽略屏蔽、隐藏以及透明窗口
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long,

ByVal yPoint As Long) As Long
'获取鼠标指针的当前位置
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As

Long
//这我为调试以上API函数建立的工程
//建立了工程一,生成了工程一.EXE文件,如下代码
Option Explicit
Dim aa As Long
//按钮单击事件
Private Sub Command1_Click()
aa = aa + 1
Text1.Text = aa
End Sub
//按钮按下事件

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As

Single, Y As Single)
aa = aa + 1
Text1.Text = aa
End Sub
//按钮松开事件
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As

Single, Y As Single)
aa = aa + 1
Text1.Text = aa
End Sub

//建立了工程二,如下代码

Option Explicit
  Private Type POINTAPI
      x As Long
      y As Long
End Type
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal

hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As

Long
'返回包含了指定点的窗口的句柄。忽略屏蔽、隐藏以及透明窗口
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long,

ByVal yPoint As Long) As Long
'获取鼠标指针的当前位置
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As

Long

'常数
Const VK_CAPITAL = &H14
Const WM_CHAR = &H102
Const HTCAPTION = 2
Const WM_NCLBUTTONDOWN = &HA1
Const WM_KEYDOWN = &H100
Const VK_DELETE = &H2E
Const VK_INSERT = &H2D
'鼠标按下
Const WM_LBUTTONDOWN = &H201
'鼠标弹出
Const WM_LBUTTONUP = &H202
'鼠标双击
Const WM_COMMAND = &H203

Private Sub Form_Load()
Timer1.Interval = 50
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim xy As POINTAPI '(声明变量类型)
Dim cc As Long
Dim bb As Long
Dim dd As Long
Dim tt As String
Dim aa As String * 256
Timer1.Enabled = False

'(取得XY的座标)
GetCursorPos xy
'(取得当前鼠标坐标下窗口的句柄)
cc = WindowFromPoint(xy.x, xy.y)
'当前鼠标坐标下窗口的句柄的名称
bb = GetWindowText(cc, aa, 255)
Text1.Text = cc
Text2.Text = aa

Timer1.Enabled = True
End Sub

Private Sub Command1_Click()

Dim dd As Long
Dim bb As Long
'Text3.Text手动输入工程一中的按钮一的句柄
bb = CLng(Text3.Text)

'发送按钮按下消息
dd = SendMessage(bb, WM_LBUTTONDOWN, 0, 0)
//这时我通过执行工程一的中断发现,按钮按下事件这段代码被触发
//  Private Sub Command1_MouseDown(Button As Integer,
//     Shift As Integer, X As Single, Y As Single)
//     aa = aa + 1
//    Text1.Text = aa
// End Sub

//Text4.Text用于改变按钮按下松开的间隔时间
Timer2.Interval = CInt(Text4.Text)
Timer2.Enabled = True
End Sub

Private Sub Timer2_Timer()
Dim bb As Long
Dim dd As Long
Timer2.Enabled = False

'Text3.Text手动输入工程一中的按钮一的句柄
bb = CLng(Text3.Text)
'发送按钮松开消息
dd = SendMessage(bb, WM_LBUTTONUP, 0, 0)
//这时我通过执行工程一的中断发现,按钮松开事件这段代码被触发
//按钮松开事件
//Private Sub Command1_MouseUp(Button As Integer,
//            Shift As Integer, X As Single, Y As Single)
//      aa = aa + 1
//      Text1.Text = aa
// End Sub

End Sub

我的问题是:
1.为什么按钮单击Command1_Click()事件不会触发?
Private Sub Command1_Click()
aa = aa + 1
Text1.Text = aa
End Sub
2.是否SendMessage函数的四个参数设定有关?
ByVal hwnd As Long,
ByVal wMsg As Long,
ByVal wParam As Long,
lParam As Long
3.wParam\lParam 参数使用详细资料哪里可以找到?

 

 

经过本人日夜奋战,终于搞定
原来是API声明中错了:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal

hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As

long

lParam As Long 改成ByVal lParam As Long 就好了.
这样一来一来值传递就变成了地址传递.
我这个程序其它部分都是可行的.
密码暴力破解中,输入密码(可用密码字典)后进行程序确定,就是用了这个程序的原理.
仅供学习参考.
谢谢大家! 可以发信 work110@126.com  联系

  评论这张
 
阅读(2220)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018