Windows API and Callback Functions

V

Vincent

I have a chunk of code that is calling the EnumWindows function that is
part of the Windows API. This function requires a callback function as
one of its parameters. The code for my callback function is as
follows:

'********************************************************************************************************
Public Function EnumWindowProc(ByVal hwnd As Long, ByVal lParam As
Long) As Long
Dim ret As Long
Dim strClass As String

strClass = Space$(256)

ret = GetClassName(hwnd, strClass, Len(strClass))
If (ret) Then strClass = Left$(strClass, ret)
Debug.Print str$(hwnd) + " - " + strClass
If strClass = "AMisBehavedApplication" Then
If (Not IsWindowVisible(hwnd)) Then SendMessage hwnd, WM_CLOSE,
0, 0
End If

EnumWindowsProc = 1
End Function
'********************************************************************************************************
From what I have read, the EnumWindows function should repeatedly call
the callback function until the callback function returns a value of
false or all windows have been enumerated. When I run my code, the
callback function is only called once. Why is this occurring? Any
help is appreciated. Thank you.

-Vincent
 
J

Jezebel

This looks like a cludge of the code posted on the vbAccelerator website.
You should read the rest of the article.
 
V

Vincent

Instead of being presumptuous and cryptic, how about being remotely
helpful. I found most of this code on another Usenet posting. I do
not know what article you are referring to.

-Vincent
 
V

Vincent

Well this "cludge" works fine. After fuming over your inconsiderate
post, I realized that the name of my callback function does not match
the name of the variable I was setting a value to at the end. Thanks
for your "help."

-Vincent
 
K

Karl E. Peterson

Vincent said:
Well this "cludge" works fine. After fuming over your inconsiderate
post, I realized that the name of my callback function does not match
the name of the variable I was setting a value to at the end.

Ouch! If that doesn't teach ya (sorry <g>) to use Option Explicit, can't
imagine what might!

Glad you got that sorted. Couldn't help mentioning the above, as this is
just a "poster child" case for why it's so crucial to use in nearly all
cases.
 
V

Vincent

I normally do use option explicit. It being left out was an oversight
on my part.

-Vincent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top