首页
社区
课程
招聘
[求助]你看看我这个自动单击MessageBox对话框中的Yes按钮的代码,哪里不对?
发表于: 2010-11-6 10:23 6289

[求助]你看看我这个自动单击MessageBox对话框中的Yes按钮的代码,哪里不对?

2010-11-6 10:23
6289
你看看我这个自动单击MessageBox对话框中的Yes按钮的代码,哪里不对?
Private Sub Timer2_Timer()
  Dim hWnd2 As Long
  Dim hWnd3 As Long
  Dim hWnd4 As Long
  

  hWnd2 = FindWindow("#32770", "标题")
  hWnd3 = FindWindowEx(hWnd2, 0, "Button", "是(&Y)")
  hWnd4 = GetWindowLong(hWnd3, GWL_ID)  '取按钮ID
  
  If hWnd4 Then
    m = SendMessage(hWnd2, &H201, hWnd4, 0)  '发送按钮按下
    n = SendMessage(hWnd2, &H202, hWnd4, 0)
    Debug.Print m, n
  End If
End Sub
Private Sub Command2_Click()
  MessageBox Form1.hwnd, "这里是内容", "标题", vbYesNo
End Sub

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (16)
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
2
Private Sub Timer2_Timer()
  Dim hWnd2 As Long
  Dim hWnd3 As Long
  Dim hWnd4 As Long
  

  hWnd2 = FindWindow("#32770", "标题")
  hWnd3 = FindWindowEx(hWnd2, 0, "Button", "是(&Y)")
  hWnd4 = GetWindowLong(hWnd3, GWL_ID)  '取按钮ID
  
  If hWnd3 Then
    m = SendMessage(hWnd3, &H201, 0, &h50005)  '发送按钮按下
   n = SendMessage(hWnd3, &H202, 0, &h50005)

     Debug.Print m, n
  End If
End Sub
Private Sub Command2_Click()
  MessageBox Form1.hwnd, "这里是内容", "标题", vbYesNo
End Sub
2010-11-6 13:16
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
这代码,啊,怎么不按下呀????
2010-11-6 13:41
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
4
检查你的API声明和参数类型相不相符。
2010-11-6 14:17
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" _
  (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, _
  ByVal wType As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
  (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  ByVal lParam As Long) 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 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_ID = (-12)
2010-11-6 14:23
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
6
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal szClsName As String, ByVal szWndName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd As Long, ByVal hClientWnd As Long, ByVal szClsName As String, ByVal szWndName As String) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function MessageBox Lib "user32.dll" Alias "MessageBoxA" (ByVal hWnd As Long, ByVal szMessages As String, ByVal szMsgTitle As String, ByVal nType As Long) As Long

Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const vbYesNo = 4

Private Sub Timer2_Timer()
  Dim hWnd2 As Long
  Dim hWnd3 As Long
  Dim hWnd4 As Long
  

  hWnd2 = FindWindow("#32770", "标题")
  hWnd3 = FindWindowEx(hWnd2, 0, "Button", "是(&Y)")
  'hWnd4 = GetWindowLong(hWnd3, GWL_ID)  '取按钮ID
  
  If hWnd3 Then
    m = SendMessage(hWnd3, WM_LBUTTONDOWN, 0, &H50015)  '发送按钮按下
    n = SendMessage(hWnd3, WM_LBUTTONUP, 0, &H50015)
    'Debug.Print m, n
  End If
End Sub
Private Sub Command2_Click()
  Timer2.Enabled = True
  MessageBox Form1.hWnd, "这里是内容", "标题", vbYesNo
  Timer2.Enabled = False
End Sub
2010-11-6 14:35
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
7
m = SendMessage(hWnd3, &H201, 0, ByVal &H50005)   '发送按钮按下
   n = SendMessage(hWnd3, &H202, 0, ByVal &H50005)
我这样弄的,弄好了
2010-11-6 14:43
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
8
是的,就是byref和byval的问题。
2010-11-6 14:48
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
9
如果我要得到YES按钮的位置坐标怎么得到呢
2010-11-6 15:40
0
雪    币: 245
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
EnumChildWindws
2010-11-6 16:17
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
11
参数50005你是怎么知道X =5,同样Y=5,你是怎么知道的呢?我有些困惑了,如果我要按下NO按钮参数又应该是多少呢?
2010-11-7 10:29
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
12
WM_LBUTTONUP and WM_LBUTTONDOWN消息的lParam参数代表着窗口的xy座标,其中lParam参数的高16位代表y座标,低16位代表x座标。xy座标的值组合成lParam的32位值算法就:(y ^ 16) or x计算出来的。所以x = 5和y = 5的座标值就是 (5 ^ 16) or 5 = &H50005。其实x = 5和y=5的座标只是我随手选的一个座标,你也可以随便选一个座标点,只要你选的座标点xy不会超过Button的Rect大小范围即可,而要知道Button的Rect大小只需使用GetClientRect函数就可以获取到。
2010-11-7 11:08
0
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
SendMessage(BM_CLICK, 0, MakeLong(5, 5));
2010-11-8 00:20
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
14
平常GetClientRect用在什么地方,有哪些用法?
2010-11-8 11:06
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
15
只要你的操作涉及到窗口区域大小范围的就需要用到它。
2010-11-8 11:32
0
雪    币: 26
活跃值: (25)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
16
不会(y ^ 16) or x的计算!
2010-11-8 12:34
0
雪    币: 2384
活跃值: (766)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
17
Dim i As Long
Dim Value As Long
Value = 5
For i = 1 To 16
  Value = Value * 2
Next i
Value = Value Or 5
MsgBox Hex(Value)
2010-11-8 12:50
0
游客
登录 | 注册 方可回帖
返回
//