LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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 ?




 
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 04:26 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"