473,803 Members | 2,946 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 5129

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
3175
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 become more clear to PGP/GnuPG users. For example, if we wrote a text on NotePad, and then select
2
2199
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
1038
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
958
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
1476
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
1769
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
1066
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 sendmessage can't read from OLE controls. If I am right, then how do I go about reading text from...
0
931
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 system call (if any exists) that displays the text? The other application is in dotnet 2.0, and...
3
3188
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
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10555
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10300
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6844
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.