vb怎么取得label的句柄

VB知道窗口句柄如何获取窗口里的所有文字?_百度知道
VB知道窗口句柄如何获取窗口里的所有文字?
我是想知道用VB如何编写能获得图片上所有的最小包装码,如有能帮到我的再追加50分!请高手们帮帮忙!
我有更好的答案
再用getwindowtext获取内容,如标签控件,按钮控件等)上的文字,你必须枚举该窗体下的子窗体后窗体上的文字,实际上在该窗体上的子窗体(就是窗体上的控件
就是如何获取这上面的所有文字,因为有下拉列表框
大体思路是这样的。。窗体上的控件,分很多种,每种控件都有各自的属性,这个是列表控件,你可以去查一下。。
采纳率:19%
255) WinTitleBuf=left( WinTitleB Alias &GetWindowTextA& _
(ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As LongDim
WinTitleBuf As String * 255GetWindowText(lhWnd, WinTitleBuf,instr(1Declare Function GetWindowText Lib &user32&quot
本回答被网友采纳
为您推荐:
其他类似问题
窗口句柄的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。VB遍历窗口下所有控件里文字
用VB怎么遍历以运行指定程序窗口下"所有控件中的文字"..比如某程序的label标签里所显示的文字...最好显示对应的控件句柄编号
就是读取另一个程序里标签显示的文字代码...
当前前提是知道窗口句柄以及控件句柄才能读取到
所以我的要求是,只获得当前窗口下label标签里的文字...
而且判断当前窗口是否是指定名称
比如我打开我刚登陆的qq 我想读到qq2008 - qq号码 这部分里显示的文字
最好发给我可以看到效果的源代码...
首先要看外部程序是什么编的,大致有以下几种情况:
1. 标签有句柄,是由 SetWindowText 实现的(其实从底层一点看,还是发送了 WM_SETTEXT
例如VC、Masm 32 的程序。这种情况好解决,GetWindowText 或 发送WM_GETTEXT消息就OK了;
2. TextOut 画上去的(例如 VB 就是这样的)。这种情况要 hook TextOut;
GetWindowText()或SendMessage()都无法取得vb程序的label的文字,因为vb的label没有handle,&
但大家发现 KingSoft CIBA 可以取得vb的label值,这是因为 KingSoft CIBA
拦下了Win32API中的textOut函数
&&&&&&&&&&&&
VB 遍历窗口下所有控件
Private Const GW_CHILD = 5
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String,
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias
"GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long)
Private Declare Function GetClassName Lib "user32" Alias
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String,
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As
Long, ByVal wCmd As Long) As Long
Private Sub FillChild(hWndParent As Long)
Dim hWndChild As Long
Dim szCaption As String
Dim buffer As String
Dim i As Long
hWndChild = GetWindow(hWndParent, GW_CHILD)
If (hWndChild = 0) Then Exit Sub
hWndChild = GetWindow(hWndChild, GW_HWNDFIRST)
If hWndChild = 0 Then Exit Sub
While (hWndChild && 0)
szCaption = String$(255, 0)
GetClassName hWndChild, szCaption, 250
szCaption = Left$(szCaption, InStr(szCaption, String$(1, 0)) -
buffer = CStr(hWndChild) & "--" &
i = GetWindowTextLength(hWndChild)
szCaption = String$(255, 0)
GetWindowText hWndChild, szCaption, 250
szCaption = Left$(szCaption, i)
buffer = buffer & "--" &
List1.AddItem buffer
FillChild hWndChild
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
Private Sub GetChildWindow(hwnd As Long)
Dim szCaption As String
Dim buffer As String
Dim i As Long
List1.Clear
szCaption = String$(255, 0)
GetClassName hwnd, szCaption, 250
szCaption = Left$(szCaption, InStr(szCaption, String$(1, 0)) -
buffer = CStr(hwnd)
buffer = buffer & "--" &
i = GetWindowTextLength(hwnd)
szCaption = String$(255, 0)
GetWindowText hwnd, szCaption, 250
szCaption = Left$(szCaption, i)
buffer = buffer & "--" &
List1.AddItem buffer
FillChild hwnd
GetChildWindow hwnd'hwnd是指定的窗口句柄
窗体句柄--窗体类名称--窗体Text
形式列在列表框List1中,没时间放到TreeView里了
只能获取有句柄项的内容,VB的Label是获取不到的,这个只能做拦截
VC的STATIC上内容可以被获取
Text的内容也无法获取,这个要靠 WM_GETTEXT来获取
Button的内容可获取
添加一个按钮,一个listview,代码如下,保证好用
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 GetParent Lib "user32" (ByVal hwnd As
Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String,
ByVal cch As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As
Long, lpRect As RECT) As Long
Private Type RECT
&& Left As Long
&& Top As Long
&& Right As Long
&& Bottom As Long
Private Type mType '自定义数据类型
&& fhwnd As Long '窗口句柄
&& fText As String * 255
&& fRect As RECT '窗口矩形
&& pHwnd As Long '父窗句柄
&& pText As String * 255
Private Sub mGetAllWindow(m_Type() As mType)
'获取控件信息,写成SUB了,其实用FUNCTION返回值也可以,只是函数里面定义就多了,总的来看需要2个mType数组,这样做只需要一个,占用空间小了
&& Dim Wndback As Long
'上一个被查找的目标句柄
&& Dim i As Long '数组控制
ReDim Preserve m_Type(i)
m_Type(i).fhwnd = FindWindowEx(0, Wndback, vbNullString,
vbNullString)
'获取hwnd,第一个参数指定为0,查找桌面子窗口,第2个参数是开始查找的窗口,第34个参数使函数查找所有窗口
If m_Type(i).fhwnd = 0 Then '=0时已经查找一遍了,退出
&&&&&&&&&&&
Else '否则获取控件相关消息
&&&&&&&&&&&
GetWindowText m_Type(i).fhwnd, m_Type(i).fText, 255 '获取标题
&&&&&&&&&&&
GetWindowRect m_Type(i).fhwnd, m_Type(i).fRect '获取RECT
&&&&&&&&&&&
m_Type(i).pHwnd = GetParent(m_Type(i).fhwnd) '获取父HWND
&&&&&&&&&&&
GetWindowText m_Type(i).pHwnd, m_Type(i).pText, 255 '获取父标题
Wndback = m_Type(i).fhwnd '保存上一个查的句柄
Private Sub Command1_Click()
&& Dim cType() As mType
&& mGetAllWindow cType()
&& Dim i As Long
ListView1.ListItems.Clear
&& For i = LBound(cType) To
UBound(cType)
ListView1.ListItems.Add , "a" & i,
cType(i).fhwnd
ListView1.ListItems("a" & i).SubItems(1) =
cType(i).fText
ListView1.ListItems("a" & i).SubItems(2) =
cType(i).fRect.Left
ListView1.ListItems("a" & i).SubItems(3) =
cType(i).fRect.Bottom
ListView1.ListItems("a" & i).SubItems(4) =
cType(i).fRect.Top
ListView1.ListItems("a" & i).SubItems(5) =
cType(i).fRect.Right
ListView1.ListItems("a" & i).SubItems(6) =
cType(i).pHwnd
ListView1.ListItems("a" & i).SubItems(7) =
cType(i).pText
Private Sub Form_Load()
&& ListView1.ColumnHeaders.Add ,
, "句柄", 1200
&& ListView1.ColumnHeaders.Add ,
, "标题", 2800
&& ListView1.ColumnHeaders.Add ,
, "Rect.Left", 800
&& ListView1.ColumnHeaders.Add ,
, "Rect.Bottom", 800
&& ListView1.ColumnHeaders.Add ,
, "Rect.Top", 800
&& ListView1.ColumnHeaders.Add ,
, "Rect.Right", 800
&& ListView1.ColumnHeaders.Add ,
, "父窗句柄", 1200
&& ListView1.ColumnHeaders.Add ,
, "父窗标题", 2800
&& ListView1.View =
&& ListView1.FullRowSelect =
&& Command1.Caption = "刷新"
EnumWindows
getwindowtext
已投稿到:API如何获取某窗体的图标句柄?_vb吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:106,830贴子:
API如何获取某窗体的图标句柄?收藏
如题…注意…窗体是属于其他进程的,可不是什么Me.Icon……还有…窗体的图标可不一定是EXE的图标…是可以实时改变的…试过GetWindowLong和GetWindowWord了,都不行…GetClassInfo也没有用……
有没有人给个思路什么的…
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const WM_GETICON = &H7FPrivate Const ICON_SMALL = 0Private Const ICON_BIG = 1Private Const ICON_SMALL2 = 2 hIcon = SendMessage(hwnd, WM_GETICON, ICON_BIG, 0&) '返回大图标
原来如此,是用SendMessage的返回值啊…受教了…
还有一类窗口使用其所属窗口类的图标,如Excel和VB,需要用下列代码获得Private Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Const GCL_HICON = (-14)
'大图标Private Const GCL_HICONSM = (-34) '小图标 hIcon = GetClassLong(hwnd, GCL_HICON)完整代码应该是先判断SendMessage返回的数值是否为0,如果为0,再使用GetClassLong返回类图标,如果依然为0,则窗口图标为windows默认程序图标(像一个空白窗体的那个,应该在Shell32.dll中)
实在是多谢了…
登录百度帐号

我要回帖

更多关于 vb 遍历窗口句柄 的文章

 

随机推荐