473,703 Members | 3,017 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 5114

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
3170
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
2190
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
1035
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
954
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
1473
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
1757
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
1058
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
928
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
3171
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
8744
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
9240
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...
1
8996
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
7846
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5920
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
4674
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2426
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2055
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.