Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Need window handle for a userform

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Need window handle for a userform

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Need window handle for a userform

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Need window handle for a userform

Hi

My own message, I would like to make a Progressform that can be updated by
posting a message with

postmessage(hWnd, WM_MY_MESSAGE_PROGRESS, iProgress, iMax)

from a "loop" where the work is done.


It seems that in VBA the system is upside down on such a thing, when most
examples are done by loading the progress form and letting the progressform
make the call back to the process function.

I don't like that, and I would like to have a progressform that is
independant of what work is to be done.


Posting a message with the progress values is so much easier.


--
Henry


"RB Smissaert" wrote:

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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Need window handle for a userform

I don't quite get what you are saying there and I don't think you need the
API to have a progressbar in Excel.
Have a look at the standard Progressbar control. I think it will do all you
want.

RBS


"Henry" wrote in message
...
Hi

My own message, I would like to make a Progressform that can be updated by
posting a message with

postmessage(hWnd, WM_MY_MESSAGE_PROGRESS, iProgress, iMax)

from a "loop" where the work is done.


It seems that in VBA the system is upside down on such a thing, when most
examples are done by loading the progress form and letting the
progressform
make the call back to the process function.

I don't like that, and I would like to have a progressform that is
independant of what work is to be done.


Posting a message with the progress values is so much easier.


--
Henry


"RB Smissaert" wrote:

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





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Need window handle for a userform

Okay, then let's stick to the question, how do I capture windows messages on
a form.


--
Henry


"RB Smissaert" wrote:

I don't quite get what you are saying there and I don't think you need the
API to have a progressbar in Excel.
Have a look at the standard Progressbar control. I think it will do all you
want.

RBS


"Henry" wrote in message
...
Hi

My own message, I would like to make a Progressform that can be updated by
posting a message with

postmessage(hWnd, WM_MY_MESSAGE_PROGRESS, iProgress, iMax)

from a "loop" where the work is done.


It seems that in VBA the system is upside down on such a thing, when most
examples are done by loading the progress form and letting the
progressform
make the call back to the process function.

I don't like that, and I would like to have a progressform that is
independant of what work is to be done.


Posting a message with the progress values is so much easier.


--
Henry


"RB Smissaert" wrote:

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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicated code window and userform window problem Zhu Excel Programming 3 November 8th 06 05:09 AM
Finding window handle of data validation listbox PastorMike[_2_] Excel Programming 2 August 18th 06 07:03 PM
How to get the window handle of and excel instance using it's process ID pmox Excel Programming 0 April 6th 06 04:35 PM
MSForms UserForm Window Handle - Win32 API Call from VBA Sean Connolly[_3_] Excel Programming 2 October 6th 05 05:10 PM
Window Handle pod Excel Programming 2 April 19th 05 10:43 PM


All times are GMT +1. The time now is 04:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"