MSForms UserForm Controls - Control IDs and Handles

S

Sean Connolly

Hello,

Is there anyone out there that can maybe help me with some tips or code to
call from VBA in order to obtain the control identifiers and handles for
controls on an MSForms UserForm? (I know that the MSForms UserForm class name
is "ThunderDFrame" and can obtain its window handle, but I'm stuck getting
any further information about the controls on that form).

Let me explain a bit further. I've created a large model/application
(xl2003, WinXP Pro) - works peachy. I've also created a compiled help file
with HTMLHelp (*.chm) - again, no problems. Declaring and then calling the
HTMLHelp API in hhctrl.ocx successfully links the compiled help topics to the
Excel application.

All great so far, but I have also created context-sensitive popup text help
which used to work great in the 'good old days' of WinHelp (*.hlp) and Help
Workshop via the "What's This" button. Things are different now.

I have written code for the MouseUp event of certain controls on the MSForms
UserForm to call the HTMLHelp API function. However, in order to correctly
display the help popup, I need to pass the relevant control's identifier and
handle to the HTMLHelp API function call.

So what I need to do (if it is even possible, or unless there is another way
that you or one of the other gurus here can advise) is obtain the window
handle of each control on the MSForms UserForm that I want to add
context-sensitive help to so that I can pass that to the GetDlgCtrlID Win32
API function and obtain the control identifier to pass to HtmlHelp. (Phew!).
Do MSForms userform controls (ListBox, CommandButton etc.) also have class
names (as for "ThunderDFrame")?

I'm continuing to search and poke around, but any further tips, assistance
or suggestions that anyone here can provide *very* gratefully received. Let
me know if more info is needed from me.

Thanks and Regards, Sean.
 
K

Karl E. Peterson

Hi Sean --
Is there anyone out there that can maybe help me with some tips or
code to call from VBA in order to obtain the control identifiers and
handles for controls on an MSForms UserForm? (I know that the MSForms
UserForm class name is "ThunderDFrame" and can obtain its window
handle, but I'm stuck getting any further information about the
controls on that form).

You'd want to call EnumChildWindows against that hWnd for the UserForm. I have an
example on my site, http://vb.mvps.org/samples/PassSniff, although it's using VB not
VBA. The theory's the same, either way, though. You just call it like:

Call EnumChildWindows(hWnd, AddressOf EnumChild, 0&)

And each child for that hWnd is passed, in turn, to this:

Private Function EnumChild(ByVal hWnd As Long, ByVal lParam As Long) As Long
' do stuff here
End Function
So what I need to do (if it is even possible, or unless there is
another way that you or one of the other gurus here can advise) is
obtain the window handle of each control on the MSForms UserForm that
I want to add context-sensitive help to so that I can pass that to
the GetDlgCtrlID Win32 API function and obtain the control identifier
to pass to HtmlHelp. (Phew!). Do MSForms userform controls (ListBox,
CommandButton etc.) also have class names (as for "ThunderDFrame")?

They sure do. Those that are windows, at least. Do you have a copy of Spy++?
That's an invaluable utility to use in uncovering these sorts of trivia, and for
testing your results, as you build stuff like this. You're stilling going to need to
perform some sort of test to identify each window uniquely, of course.

Later... Karl
 
S

Sean Connolly

Hi Karl,

Thanks for the response and help. (BTW, the website is great!).

[Working in Excel 2k3 VBA, WinXP Pro. Unfortunately no Spy++].

My MSForms UserForm contains 9 controls (listbox, command buttons etc.). I
can obtain the window handle by either of FindWindow("ThunderDFrame",
vbNullString) or FindWindow(vbNullString, "UserForm Test").

Passing this window handle to EnumChildWindows tells me that my MSForms
UserForm has only *2* child windows. Both have the class name "F3 Server
60000000", neither has a title. Passing the window handle of these child
windows to GetDlgCtrlID() returns 0 (null). I don't think either of these 2
child window handles represent controls. But neither do I get back any handle
for any of the 9 controls on my MSForms UserForm.

I seem to be back at square 1 ... :-(

I can make this process work successfully with VB forms and even Access
Forms, but I'm wondering now if MSForms UserForm controls really are
'controls' or even windows?

Have you or anyone else out there ever been able to get back the window
handle of an MSForms UserForm 'control'? If so, *please* help and/or advise
how - I'm getting desperate (not to mention unhinged)!

Thanks again and Cheers, Sean.
 
K

Karl E. Peterson

Hi Sean --

I'm still using Office 2000, as I felt that's the point they achieved "good enough!"
and hadn't yet gone into their anti-customer mode. Even still, I know that they've
very much gone towards using windowless controls. Very few on O2K userforms are
actual windows. Sounds like even fewer are in O2k3?

As for Spy++, you _really_ can't do this sort of development without a tool like
that. It's simply invaluable. There are alternatives, though. Stuff like
http://www.windows-spy.com/ -- get something, and quit wondering. :)

Later... Karl


Sean said:
Hi Karl,

Thanks for the response and help. (BTW, the website is great!).

[Working in Excel 2k3 VBA, WinXP Pro. Unfortunately no Spy++].

My MSForms UserForm contains 9 controls (listbox, command buttons
etc.). I can obtain the window handle by either of
FindWindow("ThunderDFrame", vbNullString) or FindWindow(vbNullString,
"UserForm Test").

Passing this window handle to EnumChildWindows tells me that my
MSForms UserForm has only *2* child windows. Both have the class name
"F3 Server 60000000", neither has a title. Passing the window handle
of these child windows to GetDlgCtrlID() returns 0 (null). I don't
think either of these 2 child window handles represent controls. But
neither do I get back any handle for any of the 9 controls on my
MSForms UserForm.

I seem to be back at square 1 ... :-(

I can make this process work successfully with VB forms and even
Access Forms, but I'm wondering now if MSForms UserForm controls
really are 'controls' or even windows?

Have you or anyone else out there ever been able to get back the
window handle of an MSForms UserForm 'control'? If so, *please* help
and/or advise how - I'm getting desperate (not to mention unhinged)!

Thanks again and Cheers, Sean.

Karl E. Peterson said:
Hi Sean --


You'd want to call EnumChildWindows against that hWnd for the
UserForm. I have an example on my site,
http://vb.mvps.org/samples/PassSniff, although it's using VB not
VBA. The theory's the same, either way, though. You just call it
like:

Call EnumChildWindows(hWnd, AddressOf EnumChild, 0&)

And each child for that hWnd is passed, in turn, to this:

Private Function EnumChild(ByVal hWnd As Long, ByVal lParam As
Long) As Long ' do stuff here
End Function


They sure do. Those that are windows, at least. Do you have a copy
of Spy++? That's an invaluable utility to use in uncovering these
sorts of trivia, and for testing your results, as you build stuff
like this. You're stilling going to need to perform some sort of
test to identify each window uniquely, of course.

Later... Karl
 

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