View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Need window handle for a userform

Haven't got that ready no. What messages are you interested in?

RBS


"Henry" wrote in message
...
Hi

Thanks!

Do you also happen to know how I can capture the "postmessage" message on
the form?

Must be some kind of hook right?


--
Henry


"RB Smissaert" wrote:

In a normal module:
--------------------------------

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Function GetFormHwnd(strCaption As String) As Long
If Val(Application.Version) = 9 Then
GetFormHwnd = FindWindow("ThunderDFrame", strCaption)
Else
GetFormHwnd = FindWindow("ThunderXFrame", strCaption)
End If
End Function


In your form module:
-------------------------------------

Private lFormHwnd As Long

Public Property Let propFormHwnd(lHwnd As Long)
lFormHwnd = lHwnd
End Property

Public Property Get propFormHwnd() As Long
propFormHwnd = lFormHwnd
End Property

Private Sub Userform_Initialize()

Dim hwnd As Long

hwnd = GetFormHwnd(Me.Caption)
Me.propFormHwnd = hwnd

End Sub

This will give your form a property propFormHwnd (will show up with
intelli-sense) and that can be useful for other purposes.
If you don't want this then just use the function.


RBS


"Henry" wrote in message
...
Hi

I would like the window handle of a (user)form in my excel project, how
do
I
get that?

I need to use sendmessage to that form.


--
Henry