Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Reading text labels from a Win32 window

Reply
Thread Tools

Reading text labels from a Win32 window

 
 
geskerrett@hotmail.com
Guest
Posts: n/a
 
      11-28-2006
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.

 
Reply With Quote
 
 
 
 
jUrner@arcor.de
Guest
Posts: n/a
 
      11-28-2006

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

 
Reply With Quote
 
 
 
 
Thomas Heller
Guest
Posts: n/a
 
      11-29-2006
schrieb:
> 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")

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"pointlabel"-like function for Python: distribute text labels on a2-d scatter plot to avoid overlapping labels C Barrington-Leigh Python 1 09-12-2010 09:58 PM
Win32::Printer -> override the window printer window diavolo-verde@libero.it Perl Misc 5 07-26-2006 08:54 PM
two labels in the window but in diferent time rrosa@usp.br Python 1 06-09-2005 04:40 AM
Labels not displayed when using Win32::MsgBox, more information provided hurluberlu Perl Misc 1 12-20-2004 08:36 AM
labels not displayed when using win32::MsgBox on WIN XP hurluberlu Perl Misc 1 12-17-2004 03:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57