473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Reading text labels from a Win32 window

Does anyone know of a way to read text labels from a Win32 application.
I am familiar with using pywin32 and the SendMessage function to
capture text from Buttons,text boxex, comboboxes, etc, however, the
text I am would like to capture doesn't appear to be in a control.

Nov 28 '06 #1
2 5084

ge********@hotmail.com schrieb:
Does anyone know of a way to read text labels from a Win32 application.
I am familiar with using pywin32 and the SendMessage function to
capture text from Buttons,text boxex, comboboxes, etc, however, the
text I am would like to capture doesn't appear to be in a control.

This article tells the whole story

"The secret life of GetWindowText"
http://blogs.msdn.com/oldnewthing/ar.../21/54675.aspx

And for the headaches, see

"How to retrieve text under the cursor"
http://blogs.msdn.com/oldnewthing/ar...23/118893.aspx
Anyway, msdn is the better address for problems like these.

Regards Jürgen

Nov 28 '06 #2
jU****@arcor.de schrieb:
ge********@hotmail.com schrieb:
>Does anyone know of a way to read text labels from a Win32 application.
I am familiar with using pywin32 and the SendMessage function to
capture text from Buttons,text boxex, comboboxes, etc, however, the
text I am would like to capture doesn't appear to be in a control.


This article tells the whole story

"The secret life of GetWindowText"
http://blogs.msdn.com/oldnewthing/ar.../21/54675.aspx
Appended is a script that is a fairly straight-forward conversion of the
code in the above article to Python. Needs ctypes and comtypes.

Python 2.5 already includes ctypes; comtypes can be installed
with 'easy_install comtypes'.

Thomas

import sys, time
from ctypes import windll, oledll, WinError, byref, POINTER
from ctypes.wintypes import POINT

from comtypes import COMError
from comtypes.automation import VARIANT
from comtypes.client import GetModule

# create wrapper for the oleacc.dll type library
GetModule("oleacc.dll")
# import the interface we need from the wrapper
from comtypes.gen.Accessibility import IAccessible

def GetCursorPos():
"Return the cursor coordinates"
pt = POINT()
if not windll.user32.GetCursorPos(byref(pt)):
raise WinError()
return pt.x, pt.y

def AccessibleObjectFromPoint(x, y):
"Return an accessible object and an index. See MSDN for details."
pacc = POINTER(IAccessible)()
var = VARIANT()
oledll.oleacc.AccessibleObjectFromPoint(POINT(x, y), byref(pacc), byref(var))
return pacc, var

if __name__ == "__main__":
while 1:
time.sleep(1)
x, y = GetCursorPos()

try:
pacc, index = AccessibleObjectFromPoint(x, y)
name = pacc.accName[index]
except (WindowsError, COMError), details:
print details
continue
if name is not None:
print "===", (x, y), "=" * 60
print name.encode(sys.stdout.encoding, "backslashreplace")

Nov 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RPK | last post by:
Hi, My VB application starts in System Tray, and I want that as user selects an option from the menu, the text in any window opened on desktop should automatically get selected and transferred to...
2
by: Juan Garcia | last post by:
Subject says it all. Given: Window A with text field. Window B with a button (onClick opens Window C) Window C with a button (onClick I want it to modify text fields of Window A) I have...
0
by: Davinia | last post by:
Hi, could you tell me how can I write text in a window? I've created a derived class of CMDIChild (MyWindow.cpp, MyWindow.h) and I want to write in that window but I don't know how. I've...
1
by: Paul Bromley | last post by:
Can anyone tell me if there is an easy way to capture the text from a window that is running in an external application? Best wishes Paul Bromley
1
by: peter_k | last post by:
Hi I was programming a lot in C When i wanted to make text label i was using something like: #define MY_PROGRAM_RESULTS "Result of the program = %d\n" printf(MY_PROGRAM_RESULTS, result); ...
1
by: Opettaja | last post by:
How would I go about changing text labels on a parent form from a child? For example Changing text labels on Form1 from Form2, and Form2 is opened from Form1? Any suggestions would be greatly...
0
by: Richie | last post by:
I'm trying to write a VB.net (VB.Net 2005 Express) application that scans open applications for certain words or phrases. I've successfully managed to get it to read textboxes, labels, etc in...
0
by: Amedeo Storni | last post by:
I would like my C# program to "read" the text that is printed on a particular window (from another application). I know the exact position of the text on the window, and the proportional font that...
3
by: jasvinder singh | last post by:
Respected Sir/madam, Can you help in providing code in 'C' for Reading text file with n number of rows and columns and putting the result in arrays.The sample file is as follows: rim_label =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.