| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5235 人关注过本帖
标题:如何实现vb 模拟鼠标点击其他应用程序内的命令按键
只看楼主 加入收藏
kings12333
Rank: 2
等 级:论坛游民
帖 子:114
专家分:66
注 册:2012-11-29
收藏
得分:0 
回复 20楼 yuma
如果找到Toolbar 子按钮的ID是否可以操作它?
2022-05-22 13:45
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
线程ID、进程ID 可以控件程序的运行状态,如进程挂起,进程结束,查看进程运行时长等信息。
有句柄号,窗口类名的话。可以向句柄号或窗口类名发各种API消息实现控制。

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2022-05-22 14:22
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
您正在谈论的控件正在使用ToolbarWindow32类。如果要与他们互动,则需要使用工具栏控件的API /消息。例如,要启用按钮,您想使用TB_ENABLEBUTTON。  

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2022-05-22 16:39
kings12333
Rank: 2
等 级:论坛游民
帖 子:114
专家分:66
注 册:2012-11-29
收藏
得分:0 
回复 22楼 yuma
找个ToolBar按钮,用SP++看看就知道子按钮根本没有句柄,没有句柄,常规的API操作不了它
2022-05-22 17:23
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
可能是绘制的按钮,不是控件,所以没有句柄。

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2022-05-22 17:40
kings12333
Rank: 2
等 级:论坛游民
帖 子:114
专家分:66
注 册:2012-11-29
收藏
得分:0 
回复 25楼 yuma
有没有找ToolBar 里面子按钮ID的案例或代码。。
2022-05-22 22:23
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
网上很多,但代码无法正常运行。百度搜索:VB ToolbarWindow32     看一下。

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2022-05-23 18:32
kings12333
Rank: 2
等 级:论坛游民
帖 子:114
专家分:66
注 册:2012-11-29
收藏
得分:0 
回复 27楼 yuma
谢谢 yuma..百度找到一篇文章可以改变TooBar的状态,但发送点击命令似乎无效,帮看看。谢谢!
程序代码:
============下面附上TB_ENABLEBUTTON源码,这个是成功的~


Option Explicit
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 GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Const PROCESS_ALL_ACCESS = &H1F0FFF

Private Const MEM_COMMIT = &H1000
Private Const MEM_DECOMMIT = &H4000

Private Const PAGE_READWRITE = &H4&

Private Const WM_USER As Long = &H400
Private Const TB_GETBUTTON As Long = (WM_USER + 23)
Private Const TB_ENABLEBUTTON As Long = (WM_USER + 1)

Private Type TBBUTTON
iBitmap As Long
idCommand As Long
fsState As Byte
fsStyle As Byte
bReserved(1) As Byte
dwData As Long
iString As Long
End Type

Private Function MAKELONG(ByVal a As Long, ByVal b As Long) As Long
MAKELONG = (b And &HFFFF&) * &H10000 + (a And &HFFFF&)
End Function

Function EnableTBButtion(ByVal hTBWnd As Long, ByVal lIndex As Long, Optional fEnabled As Boolean = True, Optional fIsIndex As Boolean = True) As Long
Dim utBtn As TBBUTTON
Dim lButtonID As Long
Dim lpRemote_utBtn As Long
Dim lProcessId As Long, hProcess As Long
hTBWnd = Text1.Text
Call GetWindowThreadProcessId(hTBWnd, lProcessId)

If fIsIndex Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lProcessId)
If hProcess <> 0 Then
lpRemote_utBtn = VirtualAllocEx(ByVal hProcess, ByVal 0&, Len(utBtn), MEM_COMMIT, PAGE_READWRITE)
Call SendMessage(hTBWnd, TB_GETBUTTON, lIndex, ByVal lpRemote_utBtn)
Call ReadProcessMemory(ByVal hProcess, ByVal lpRemote_utBtn, utBtn, Len(utBtn), ByVal 0)
Call VirtualFreeEx(hProcess, ByVal lpRemote_utBtn, 0, MEM_DECOMMIT)
End If
CloseHandle hProcess
lButtonID = utBtn.idCommand
Else
lButtonID = lIndex
End If

EnableTBButtion = SendMessage(hTBWnd, TB_ENABLEBUTTON, lButtonID, ByVal MAKELONG(Abs(fEnabled), 0))
End Function

Private Sub Command2_Click()
'禁用第3个按钮
Debug.Print EnableTBButtion(&H17104A4, 3 - 1, False)
End Sub

Private Sub Command1_Click()
'启用第3个按钮
Debug.Print EnableTBButtion(&H17104A4, 3 - 1, True)
End Sub


2022-05-23 20:38
William1949
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:111
专家分:0
注 册:2009-3-17
收藏
得分:0 
获得 button ID,然后发 wm_command,不就行了。
wparam 的低字指定buttonId,高字为0,
lparam 指定toolbar句柄,
你上面的代码,已经可以获得id,应该不难吧。
2022-05-24 18:46
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
WIN10系统中返回0,未执行成功。
请在windows xp系统,甚至更低版本的系统中测试,使用管理员权限或许能成功。
不知你测试的是哪里的ToolBar
网上很多代码是以前的代码,在低版本系统下能正常运行。

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2022-05-24 18:53
快速回复:如何实现vb 模拟鼠标点击其他应用程序内的命令按键
数据加载中...
 
   



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

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