Discussion:
Hooks and Accessibility, Window Sub-classing
(too old to reply)
Veli-Pekka Tatila
2004-08-30 09:17:10 UTC
Permalink
Hi,
I'm really new to Windows programming having just read some of the basics in
the Petzold book but I do know some C and C++. I'm doing a little esay on
Windows programming and have chosen accessibility in the Win32 API, as I'm
also visually impaired and planning to write a free screen reader for
Windows some day.

Anyway, my goal is to do a very simple proof-of-concept console app that
would demonstrate accessibility in Win32. A screne reader program turns the
GUI into a textual representation that's usually output through speech or
braille. In other words, it follows focus changes and reads the types and
states of the various GUI widgets out there. The closest "ordinary"
equivalent I can think of is a program that lists class names and other info
regarding a given window.

I've been browsing through MSDN and found out there's no direct support for
accessibility in the WIN32 API apart from a screen reader flag and built-in
Windows accessibility. However, it would seem to me that hooks might be the
answer here. Could anyone shed some light on or provide links regarding
hooks? A real small, basic example would be fine.

Regarding the actual implementation of my console app. If I only got the
window handle for the currently active window, I could start recursively
querying info on child windows, I suppose. Which messages notify me of
active window changes?

There are quite a number of hooks in the API and I don't fully understand
there differences. Which hooks would you recommend for getting info out of
dialogs, windows and child-windows aka widgets? Also, should I use global or
thread specific hooks? I know next to nothing about DLLs and as far as I can
tell, most screen readres only follow changes in the active window. So I
guess following a single thread of execution would probably be better and
more efficient, too.

Finally, a silly question. I've been mostly programming in object-oriented
languages like C++ and Java. If the WIn32 API was some kind of an object
hierarchy, I suppose i would handle everything through a pointer to some
window ABC, letting polymorphism take kcare of the details at runtime.
What's the equivalent of such polymorphism in a procedural language, that is
are there certain function calls that will work with all windows? Finally,
what does sub-classing mean in C and how does it work? Surely we are not
talking about actual C++ classes here but function pointers and structs.

Any help greatly appreciated.

PS: On a side note, Windows datatype names are pretty horrible with speech,
oh well <smiley>.
--
With kind regards Veli-Pekka Tätilä (***@mail.student.oulu.fi)
Accessibility, game music, synthesizers and more:
http://www.student.oulu.fi/~vtatila
Alex Blekhman
2004-08-30 16:01:11 UTC
Permalink
Post by Veli-Pekka Tatila
I've been browsing through MSDN and found out there's no direct
support for accessibility in the WIN32 API apart from a screen
reader flag and built-in Windows accessibility. However, it would
seem to me that hooks might be the answer here. Could anyone shed
some light on or provide links regarding hooks? A real small, basic
example would be fine.
Actually Windows supports quite rich accessibility functionality. Look
in MSDN for "Microsoft Active Accessibility"
<http://msdn.microsoft.com/library/en-us/msaa/msaastart_9w2t.asp>

Active Accessibility works by combination of system hooks and COM
interfaces. It can be programmed with C/C++ and VB. I don't know how
to use it from Java.
Post by Veli-Pekka Tatila
Regarding the actual implementation of my console app. If I only
got the window handle for the currently active window, I could
start recursively querying info on child windows, I suppose. Which
messages notify me of active window changes?
Your hook procedure will by called by system with certain code of
WinEvent. For example, EVENT_SYSTEM_FOREGROUND will indicate that
foreground window has changed.
Post by Veli-Pekka Tatila
There are quite a number of hooks in the API and I don't fully
understand there differences. Which hooks would you recommend for
getting info out of dialogs, windows and child-windows aka widgets?
You'll set Active Accessibility hook with SetWinEventHook function.
Post by Veli-Pekka Tatila
Also, should I use global or thread specific hooks? I know next to
nothing about DLLs and as far as I can tell, most screen readres
only follow changes in the active window. So I guess following a
single thread of execution would probably be better and more
efficient, too.
If you want to hook a windows that belongs to other application (i.e.
process), then you'll need to implement hook procedure in separate
DLL, so system will be able to load it in context of other process.
You can install hook for specific thread, however if focus will move
to a window from other thread, your hook procedure will not be called.
Post by Veli-Pekka Tatila
Finally, a silly question. I've been mostly programming in
object-oriented languages like C++ and Java. If the WIn32 API was
some kind of an object hierarchy, I suppose i would handle
everything through a pointer to some window ABC, letting
polymorphism take kcare of the details at runtime. What's the
equivalent of such polymorphism in a procedural language, that is
are there certain function calls that will work with all windows?
Finally, what does sub-classing mean in C and how does it work?
Surely we are not talking about actual C++ classes here but
function pointers and structs.
I'm not sure that I fully understand you here. But Windows subclassing
is realy simple thing. Windowing in Windows was designed when primary
programming language was C. However, windowing subsystem is built with
object-oriented approach in mind.

Before you create a window, you need to inform system about properies
that this window will carry. The same as in C++, before creating an
instance you need to define class. You decide which properties to use
with window (such as class name, window background, icon and most
important - window procedure), then call RegiitserClass[Ex]. From now
system knows how to create windows of your class. Then you call to
CreateWindow(classname, ...), so system creates new window. From this
moment new window can process events like mouse-over or
change-of-focus. System will call your windows procedure with numeric
codes of events. Window procedure is plain C function with specific
signature as documented in MSDN.

When your process starts there are already several predefined classes
which Windows implements for you: Edit, Button, ComboBox etc.. For
each of these classes USER32.DLL implements default window procedure.
If you want extended or nonstandard functionality for some class, then
you can replace default window procedure for the class with your own.
Inside your custom procedure you decide for each message whether to
pass it to default procedure or to handle yourself (or both).

"Subclassing a Window"
<http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterf
ace/windowing/windowprocedures/usingwindowprocedures.asp?frame=true#su
bclassing_window>
Veli-Pekka Tatila
2004-08-31 09:04:44 UTC
Permalink
Post by Alex Blekhman
Actually Windows supports quite rich accessibility functionality. Look
in MSDN for "Microsoft Active Accessibility"
I know about MSAA from the user-perspective, but I'm doing this essay
strictly about the WIn32 API rather than say MFC. And I know there were
screen readeres for 95 before MSAA came about, so it cannot be the only way,
though of course nowadays recommended and quite useful.
Post by Alex Blekhman
If you want to hook a windows that belongs to other application (i.e.
process), then you'll need to implement hook procedure in separate
DLL,
Oh ok, thanks for the clarification. I thought I could do it on a per thread
basis and then just change threads when-ever the active window changes but i
guess it won't work like that after all.
Post by Alex Blekhman
object-oriented approach in mind.
But if this object-orientation is done in C, how does it work and does it
support polymorphism in some way? How does it know that everything derived
from some built-in window can be handled the same way, even if I add new
data members?
--
With kind regards Veli-Pekka Tätilä (***@mail.student.oulu.fi)
Accessibility, game music, synthesizers and more:
http://www.student.oulu.fi/~vtatila
Alex Blekhman
2004-08-31 15:12:08 UTC
Permalink
Post by Veli-Pekka Tatila
Post by Alex Blekhman
Actually Windows supports quite rich accessibility functionality.
Look in MSDN for "Microsoft Active Accessibility"
I know about MSAA from the user-perspective, but I'm doing this
essay strictly about the WIn32 API rather than say MFC.
MSAA doesn't require MFC. MFC is just a framework of C++ classes that
encapsulate Win32 API. There is nothing you able to do with MFC that
you couldn't do with plain Win32 API. MFC just saves you lines of
code. However, MSAA requires COM. You can do COM from plain C, but
this is really cumbersome and unpractical. COM with C++ is much easier
even if you don't use any libraries (such as ATL, for example).
Post by Veli-Pekka Tatila
Post by Alex Blekhman
object-oriented approach in mind.
But if this object-orientation is done in C, how does it work and
does it support polymorphism in some way?
It works by accessing any window by means of unified handle (HWND
type) and using the same functions for any window. Any window is
created with CreateWindow[Ex] and you can send/post messages to any
window, too. What certain window will actually do with these messages
depends on its implementation (i.e. window class).
Post by Veli-Pekka Tatila
How does it know that
everything derived from some built-in window can be handled the
same way, even if I add new data members?
You can't add new data members, but you can change existing ones.
Also, you can ask system to allocate more bytes than necessary for
internal structure that holds window's information. In this extra
memory you can store whatever you want.

Loading...