200分相送,如何获取正在运行的其他程序窗口中的文本内容!

wenw 2002-07-18 10:58:55
我们很容易获得正在运行的其他程序窗口的句柄和窗口标题,可是,我们怎么样获得它中间文本的内容呢?
...全文
267 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenw 2002-07-19
  • 打赏
  • 举报
回复
函数功能:该函数将指定窗口的标题条文本(如果存在)拷贝到一个缓存区内。如果指定的窗口是一个控制,则拷贝控制的文本。但是,GetWindowTeXt不能接收在其他应用程序中的控制文本。

我是要接收在其他应用程序中的弹出窗体的文本内容,该怎么办呢?
wenw 2002-07-19
  • 打赏
  • 举报
回复
问题已经解决,结帐!
40Star 2002-07-18
  • 打赏
  • 举报
回复
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
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


Const WM_GETTEXTLENGTH = &HE
Const WM_GETTEXT = &HD

Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Timer1_Timer()
Dim P As POINTAPI
Dim H As Long
GetCursorPos P
H = WindowFromPoint(P.x, P.y)

Dim L As Long
L = SendMessage(H, WM_GETTEXTLENGTH, 0, 0)

Dim t As String
t = Space(1000)
SendMessageByStr H, WM_GETTEXT, 1000, t
Text1.Text = t
End Sub
wenw 2002-07-18
  • 打赏
  • 举报
回复
例如对话框,我获得了句柄,该怎么得到它的提示内容呢?
Ranma_True 2002-07-18
  • 打赏
  • 举报
回复
先用spy++查出目标文本所在控件的类,然后根据这个类名称获得
此控件的句柄。
不知此方法是否可行。
KAIBate 2002-07-18
  • 打赏
  • 举报
回复
关注。:)
dsclub 2002-07-18
  • 打赏
  • 举报
回复
啊,对不起。如果你是想要“文本内容”那GETWINDOWTEXT是可以的,我看错了。为了表达歉意:
'Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Sub GetCursorPos Lib "user32" (lpPoint As POINTAPI)
Private Declare Function WindowFromPoint Lib "user32" (ByVal ptY As Long, ByVal ptX As Long) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) 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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal h&, ByVal hb&, ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, ByVal f&) As Long
Private Declare Function GetActiveWindow& Lib "user32" ()

Const GWW_HINSTANCE = (-6)
Const GWW_ID = (-12)
Const GWL_STYLE = (-16)
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Const SW_MINIMIZE = 6




Private Sub Form_Load()

'This centers the form. I usually add a function to center
'a form but since this is just a one-form kinda program,
'I just put it here.
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2

'This calls the StayOnTop function. You can find this
'particular function under every rock and in just about
'every book on Visual Basic. :)
StayOnTop Me

End Sub

Private Sub Label1_Click()
End
End Sub

'使本窗体alwaysontop
Private Sub StayOnTop(frm As Form)

Dim success&
success& = SetWindowPos(frm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)

End Sub

Private Sub Timer1_Timer()

'Among the things I played with was removing the Hex function from
'this code. Personally, I don't care much about Hex values. If that
'kind of thing floats *your* boat, pull out the KB article and
'change it back. :)

Dim ptCursor As POINTAPI
Dim sWindowText As String * 100
Dim sClassName As String * 100
Dim hWndOver As Long
Dim hWndParent As Long
Dim sParentClassName As String * 100
Dim wID As Long
Dim lWindowStyle As Long
Dim hInstance As Long
Dim sParentWindowText As String * 100

Dim sModuleFileName As String * 100
Static hWndLast As Long

Call GetCursorPos(ptCursor) ' Get cursor position
hWndOver = WindowFromPoint(ptCursor.x, ptCursor.y) ' Get window cursor is over
If hWndOver <> hWndLast Then ' If changed update display
hWndLast = hWndOver ' Save change
Cls ' Clear the form
Print "Window Handle: "; (hWndOver) ' Display window handle
Print "Focus: "; GetActiveWindow() 'I added this
r = GetWindowText(hWndOver, sWindowText, 100) ' Window text
Print "Window Text: " & Left(sWindowText, r)

r = GetClassName(hWndOver, sClassName, 100) ' Window Class
Print "Window Class Name: "; Left(sClassName, r)

lWindowStyle = GetWindowLong(hWndOver, GWL_STYLE) ' Window Style
Print "Window Style: "; (lWindowStyle)

' Get handle of parent window:
hWndParent = GetParent(hWndOver)

' If there is a parent get more info:

If hWndParent <> 0 Then
' Get ID of window:
wID = GetWindowWord(hWndOver, GWW_ID)
Print "Window ID Number: "; (wID)
Print "Parent Window Handle: "; (hWndParent)

' Get the text of the Parent window:
r = GetWindowText(hWndParent, sParentWindowText, 100)
Print "Parent Window Text: " & Left(sParentWindowText, r)

' Get the class name of the parent window:
r = GetClassName(hWndParent, sParentClassName, 100)
Print "Parent Window Class Name: "; Left(sParentClassName, r)
Else
' Update fields when no parent:
Print "Window ID Number: N/A"
Print "Parent Window Handle: N/A"
Print "Parent Window Text : N/A"

Print "Parent Window Class Name: N/A"
End If

' Get window instance:
hInstance = GetWindowWord(hWndOver, GWW_HINSTANCE)

' Get module file name:
r = GetModuleFileName(hInstance, sModuleFileName, 100)
Print "Module: "; Left(sModuleFileName, r)
End If



End Sub

anywayliu 2002-07-18
  • 打赏
  • 举报
回复
你是什么意思?是得到另一窗体的文本框的内容吗?
如是只须窗体名.文本框控件名即可,如:frm.text1
anywayliu 2002-07-18
  • 打赏
  • 举报
回复
你是什么意思?是得到另一窗体的文本框的内容吗?
如是只须窗体名.文本框控件名即可,如:frm.text1
dsclub 2002-07-18
  • 打赏
  • 举报
回复
不能用GETWINDOWTEXT

那个函数只能得到控件被置值后的TEXT内容.


chenyu5188 2002-07-18
  • 打赏
  • 举报
回复
用API, GETWINDOWTEXT
lou_df 2002-07-18
  • 打赏
  • 举报
回复
得到窗口的句柄后,取窗口的文本.
guiqing 2002-07-18
  • 打赏
  • 举报
回复
40Star(陪你去看--☆流星雨★) 说的方法就可以,不过这种方法在2000和XP下得不到类名为Edit框的文本内容,有谁知道顺便答复。谢谢。
还有用getwindowtext可以直接得到窗口名。
spy++是vs里的一个小程序,是用来看句柄和类名等的。它是独立程序,可以找一个来用。
renyao 2002-07-18
  • 打赏
  • 举报
回复
请问SPY++是什么?
在VB里怎么用SPY++?
网络咖啡 2002-07-18
  • 打赏
  • 举报
回复
学习
NowCan 2002-07-18
  • 打赏
  • 举报
回复
你的意思是不是,比如要得到一个MessageBox里的文字?
NowCan 2002-07-18
  • 打赏
  • 举报
回复
你的意思是不是,比如要得到一个MessageBox里的文字?
我将带领大家来系统学习Windows的窗口编程,包括消息、窗口、GDI绘图、游戏开发等。本课程比较基础,非常适合初学者入门,读者可以边学习边实践。具体的章节目录和课程内容如下所示:---------------------------------------------Windows游戏编程系列之1:GUI界面编程及游戏入门实战1、Windows创建第一个窗口 WinMain入口函数 5进行Windows编程的调试手法 6窗口从哪里来? 7窗口编程的步骤 7窗口编程需要的主要结构 8窗口编程需要的主要API 92、Windows的窗口过程与消息机制 如何留住窗口? 121)Windows的消息与消息循环 142)消息处理函数与常用消息 17)Windows的窗口过程函数 19 3、GDI编程之设备上下文 1)GDI的通用编程框架 222)GDI的绘图步骤 253)GDI获取设备句柄 254、GDI编程之绘制几何图形 画点、线 28颜色COLORREF 29矩形 29画圆、饼图、弦图 305、GDI编程之自定义画笔画刷画笔简介 32画刷简介 33画笔案例 33画刷案例 346、GDI编程之绘制文字 DrawText函数 35TextOut 函数 (wingdi.h) 36CreateFont函数 37绘制文本案例 377、GDI编程之绘制位图 位图简介 381)在资源添加位图资源 392)从资源加载位图: LoadBitmap 393)创建一个与当前DC相匹配的DC(内存DC) 394)将bitmap放入匹配的DC:SelectObject 405)成像(1:1 比例 ) 406)取出位图 407)释放位图 418)释放匹配的DC 41绘制位图案例 41   8、Windows鼠标键盘消息 一、键盘消息 421、键盘消息 422、消息参数: 423、消息的使用: 424、键盘消息的案例代码 43二、鼠标消息 441、基本鼠标消息 442、双击消息 443、滚轮消息 454、不响应双击消息 45 9、Windows定时器消息 定时器消息介绍 47创建定时器 47关闭定时器 47定时器消息案例代码 4810、GDI游戏之跳舞动画 11、GDI游戏之走路动画 12、GDI贪吃蛇游戏实战  

7,759

社区成员

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

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