Window Class of UserForm controls
Here is a way to get the hWnd of userfcorm controls.
First create a class, I call it clsHWnd, with this simple code
Option Explicit
Public Name As String
Public hWnd As Long
Then in the userform, declare a couple of APIs and a collection
Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private ListBoxCollection As Collection
and load it in the initialize event; add this
Private Sub Userform_Initialize()
Dim ctl As msforms.Control
Dim listHWnd As clshWnd
Dim meHWnd As Long
Dim res As Long
meHWnd = FindWindow("ThunderDFrame", Me.Caption)
If meHWnd = 0 Then
Exit Sub
End If
Set ListBoxCollection = New Collection
For Each ctl In UserForm1.Controls
ctl.SetFocus
Set listHWnd = New clshWnd
listHWnd.hWnd = GetFocus
listHWnd.Name = ctl.Name
ListBoxCollection.Add Item:=listHWnd, Key:=listHWnd.Name
Next ctl
End Sub
You can just get hWnd from the collection, like so
MsgBox ListBoxCollection("ListBox1").hWnd
--
HTH
Bob Phillips
(replace xxxx in the email address with gmail if mailing direct)
"Martin" wrote in message
...
Can anyone tell me the API Window Class of controls in a userform? Or,
even
better, point me to a definitive list of the window classes in MS Office?
I'm trying to find a way to to identify the hWnd of the active control
(not
easy in VBA) so I can use context sensitive help.
|