Before starting this lesson, make sure you have read and understood the Intro
lesson. If you haven't gotten a copy, email or IM me for it.

Ok, in the first lesson we learned what a handle and a child are, and a
little on how to locate these using different functions available in Windows
API. This lesson will go a little deeper into the FindChildByClass and
FindChildByTitle functions, as well as a little on sending messages to items
using API.

Neither of the FindChild functions are directly available in Windows API. You
have to either make your own using a few functions that are available in the
Windows API or use the ones in VBWFIND.DLL. The ones in VBWFIND.DLL are
supposedly not too efficient. I've never used them myself though. Anyway,
there are a few functions you should look up in your API help file now. These
are

GetWindow
GetWindowText
GetClassName

By their titles you should almost know what they do. There are also a few
constants you need. These are also available in the API Help file.

GW_CHILD
GW_HWNDNEXT

And one VB function you should learn

String$( )

Get all these and then read on. Lets use the same MDIClient we used in the
last lesson.

MDI% = FindChildByClass(AOLhandle%, "MDIClient")

What you would want your function to do here is to look at every child under
AOL and find one that has a classname of "MDIClient". We can do this by
looping through each child window, using our GetClassName function to look at
its class name, and then compare it against the class name that we're looking
for. Lets say our FindChildByClass function starts like this

Function FindChildByClass(Parent%, ClassToFind$) As Integer

Our function would then want to look the child items/forms under Parent% and
compare their class names against ClassToFind$. To find the first child of
Parent% we have to use

Childhandle% = GetWindow(Parent%, GW_CHILD)

and to get the class name of this child window we would use this thread of
code.

ChildClass$ = String$(200, 0)      <--this puts 200 null characters into the
variable                                                      because
GetClassName wants some space
                                                     to put the class name
into.
Dummy% = GetClassName(Childhandle%, ChildClass$, 199)
                                                     This tells Windows to
look at Childhandle%,
                                                     get its class name, and
put it into ChildClass$,
                                                     but cut it off if its
longer than 199 characters
                                                     (will never happen), and
the length is in Dummy%
ChildClass$ = Left$(ChildClass$, Dummy%)
                                                     Cuts all the nulls off
leaving only the class name.

Then you would compare what you got in ChildClass$ with ClassToFind$ and see
if you've found your match, if not, move on to the next child

Childhandle% = GetWindow(Childhandle%, GW_HWNDNEXT)

This tells Windows to look at Childhandle%, find the next child window in
order, and return it in Childhandle% (overwriting the old one). Then you do
your GetClassName check again, and keep looping this until you find your
match or ChildHandle% = 0 which means there are no more child items (if you
havent found a match by that time, there is no match).



FindChildByTitle works basically the same way as FindChildByClass except that
it looks at the caption of the item/form and compares it against what your
looking for. You use the exact same GW_CHILD and GW_HWNDNEXT calls that you
did above, except that you dont use GetClassName, you use GetWindowText. It
goes something like this

ChildText$ = String$(200, 0)
Dummy% = GetWindowText(Childhandle%, ChildText$, 199)
ChildText$ = Left$(ChildText$, Dummy)

Then compare against what your looking for, if its not a match loop with
GW_HWNDNEXT and so on.



Finally, sending messages. This depends a lot on what kind of object your
sending a message to and what kind of message you are sending to it. I'll
start you off with a basic one. Sending text to a text box. Use what you
learned in the intro lesson and this lessons FindChildByClass to locate your
text box (Hint: all AOL text boxes have the class name "_AOL_EDIT"). Get the
declaration for this from your help file

SendMessageByString

and find this constant

WM_SETTEXT


Lets say you have the handle of your text box in EdithWnd%. Put what you want
to send into a string, lets say WhatToSend$.

X% = SendMessageByString(EdithWnd%, WM_SETTEXT, 0, WhatToSend$)

X% will be non-zero if it worked, WM_SETTEXT tells EdithWnd% to set the text
to WhatToSend$. Pretty simple. There are other ways to send messages. The
other highly used one is SendMessageByNum. If you wanted to press enter after
this you would use

X% = SendMessageByNum(EdithWnd%, WM_CHAR, 13, 0)

13 is the ascii code for the Enter key. You can also send message to things
like List boxes (LB_xxxx). The constants for these are all in your help
files. This is what I meant in the first lesson by being able to do anything
with just a few values and function calls. Everything is in the help files
and all you have to do is know when and where to use them, either by
experimenting, or asking around.

EV   iVe  
