Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default hWnd of UserForm

If I activate a UserForm in Excel, how can I access
the hWnd of that UserForm ?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default hWnd of UserForm

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

Function hWnd() As Long
Dim hWndThis As Long
If Val(Application.Version) 8 Then
hWndThis = FindWindow(lpClassName:="ThunderDFrame",
lpWindowName:=Me.Caption)
Else
hWndThis = FindWindow(lpClassName:="ThunderXFrame",
lpWindowName:=Me.Caption)
End If

hWnd = hWndThis
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"rsmith" wrote in message
...
If I activate a UserForm in Excel, how can I access
the hWnd of that UserForm ?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default hWnd of UserForm

You need to use the FindWindow API call. For example,

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

Sub AAA()
Dim HWND As Long
If Val(Application.Version) = 9 Then
HWND = FindWindow("ThunderDFrame", UserForm1.Caption)
Else
HWND = FindWindow("ThunderXFrame", UserForm1.Caption)
End If
MsgBox HWND
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"rsmith" wrote in message
...
If I activate a UserForm in Excel, how can I access
the hWnd of that UserForm ?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default hWnd of UserForm

From a post by Stephen Bullen:

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

Private Declare Function GetWindowLong Lib "user32" Alias
"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal
dwNewLong As Long) As Long

Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long)
As Long

Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION As Long = &HC00000
Private Const WS_SYSMENU As Long = &H80000

Private Sub UserForm_Activate()

Dim iStyle As Long

'Get the userform's window handle
If Val(Application.Version) < 9 Then
hWndForm = FindWindow("ThunderXFrame", Me.Caption) 'XL97
Else
hWndForm = FindWindow("ThunderDFrame", Me.Caption) 'XL2000
End If

iStyle = GetWindowLong(hWndForm, GWL_STYLE)
iStyle = iStyle And Not WS_CAPTION
iStyle = iStyle And Not WS_SYSMENU
SetWindowLong hWndForm, GWL_STYLE, iStyle
DrawMenuBar hWndForm

End Sub


Don't forget to add a way to close the form!


Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk


ThunderDFrame is for xl2000 and later

--
Regards,
Tom Ogilvy

rsmith wrote in message
...
If I activate a UserForm in Excel, how can I access
the hWnd of that UserForm ?




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
Userform Add hazel Excel Discussion (Misc queries) 8 November 3rd 06 07:01 PM
one userform to another damorrison Excel Discussion (Misc queries) 2 August 26th 06 01:10 PM
how to get hwnd from application object? Erwin Kalvelagen Excel Programming 2 December 16th 03 07:12 PM
Userform John Wilson Excel Programming 2 August 1st 03 06:33 PM
Userform RboinD Excel Programming 1 August 1st 03 02:42 PM


All times are GMT +1. The time now is 08:25 PM.

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

About Us

"It's about Microsoft Excel"