请问SendMessage 哪个wMsg常数可以获得另一个程序的button的值

hbjmdx008 2010-06-23 06:44:15
我已经得到了该buttion的句柄,mhwnd
mhwnd = FindWindowEx(demo_Hwnd, 0, "Button", vbNullString)


SendMessage( mhwnd ,?,?,?)


问号里填什么能
返回该button的值




...全文
107 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hbjmdx008 2010-06-24
  • 打赏
  • 举报
回复
 Dim ButtonText As String * 256
str = GetWindowText(ChildText_Hwnd, ByVal ButtonText, 255)
MsgBox ButtonText
hbjmdx008 2010-06-24
  • 打赏
  • 举报
回复
也感谢大家的热情解答

我再用getwindowtext也试成功了
hbjmdx008 2010-06-24
  • 打赏
  • 举报
回复
多谢东方之珠
果如您所说
谢谢
舉杯邀明月 2010-06-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hbjmdx008 的回复:]
不能用getwindowtext,因为是另一个程序的,button的,getwindowtext只能对当前程序
[/Quote]

只能说明你的用法有问题。
lyserver 2010-06-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hbjmdx008 的回复:]
注解
不能用它从另一个应用程序的编辑控件中获取文字
[/Quote]
这个说法是错误的,比如你先用SPY++获得其它程序一个窗口的句柄,然后使用GetWindowText获得窗口的标题,是可以得到标题的。
东方之珠 2010-06-24
  • 打赏
  • 举报
回复
'发一个WM_GETTEXT 消息就够了
Option Explicit

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Const WM_GETTEXT As Long = &HD&

Private Sub Command1_Click()
Dim ButtonText As String * 256
Call SendMessage(Command1.hWnd, WM_GETTEXT, 255, ByVal ButtonText)
Debug.Print "Button按钮文本:" & Left(ButtonText, InStr(ButtonText, Chr(0)) - 1)
End Sub
hbjmdx008 2010-06-24
  • 打赏
  • 举报
回复
我试一下,先谢谢了
soarsoar77 2010-06-24
  • 打赏
  • 举报
回复
获取Button上面的文字需要发2次sendmessage

第一次取上面文字的长度
Txtlen=sendmessage(mhwnd,WM_GETTEXTLENGH,0,0)
第二次才取上面的值
l=SendMessage(mhwnd,WM_GETTEXT,Textlen,ByVal Text)

最后的值在Text中
hbjmdx008 2010-06-24
  • 打赏
  • 举报
回复
GetWindowText

VB声明
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
说明
取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)
返回值
Long,复制到lpString的字串长度;不包括空中止字符。会设置GetLastError
参数表
参数 类型及说明
hwnd Long,欲获取文字的那个窗口的句柄
lpString String,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入
cch Long,lpString缓冲区的长度
注解
不能用它从另一个应用程序的编辑控件中获取文字

==============================================

我确实是取不到啊.
我取的时候返回0
lyserver 2010-06-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hbjmdx008 的回复:]
不能用getwindowtext,因为是另一个程序的,button的,getwindowtext只能对当前程序
[/Quote]
谁说getwindowtext只能对当前程序?
hbjmdx008 2010-06-24
  • 打赏
  • 举报
回复
不能用getwindowtext,因为是另一个程序的,button的,getwindowtext只能对当前程序
lyserver 2010-06-23
  • 打赏
  • 举报
回复
同上,如果是取按钮的文本,可以使用getwindowtext来获取。
a1875566250 2010-06-23
  • 打赏
  • 举报
回复
你是要获取Button的按钮文本还是勾选状态?

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧