473,554 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5099

ge********@hotm ail.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********@hotm ail.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.automa tion import VARIANT
from comtypes.client import GetModule

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

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

def AccessibleObjec tFromPoint(x, y):
"Return an accessible object and an index. See MSDN for details."
pacc = POINTER(IAccess ible)()
var = VARIANT()
oledll.oleacc.A ccessibleObject FromPoint(POINT (x, y), byref(pacc), byref(var))
return pacc, var

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

try:
pacc, index = AccessibleObjec tFromPoint(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.encodin g, "backslashrepla ce")

Nov 29 '06 #3

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

Similar topics

0
3165
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 clipboard. And, I want the reverse also. I mean text from my application to get transferred to the opened window on desktop. This question will...
2
2177
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 tried storing the handle of Window A ( var winHandle = this; ) in a global variable/file ( globals.js ) and then accessing it from
0
1033
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 prove with this: but pContext is NULL, what am I doing wrong?
1
948
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
1470
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); But this method works only when i use stdio functions... Now i have started using iostream cout<< and cin>> functions...
1
1740
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 appreciated.
0
1051
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 notepad, MS Word and Internet Explorer, but it doesn't read the main work areas of MS Office and Internet Explorer. I am guessing that this is because...
0
923
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 will be used. First idea: use OCR. Can you recommend a freely available OCR dll? Another question: are there alternatives? Like, "intercepting" the...
3
3161
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 = 'aeff5' state 0 = 'eee' state 1 = 'ffffff' . .and so on...
0
7783
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8023
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6129
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5144
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
828
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.