View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
NateBuckley NateBuckley is offline
external usenet poster
 
Posts: 146
Default Remove the X button from a user form? Api?

Excellent Stuff, Cheers.

I shall now attempt to go through that and try to understand the calls.

Thanks again!

"RB Smissaert" wrote:

To disable it you can use the Windows API:

In a normal module have this:

Option Explicit
Public Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" _
(ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" _
(ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) _
As Long
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000

Sub DisableCloseButton(hwnd As Long)

Dim hMenu As Long
Dim menuItemCount As Long

hMenu = GetSystemMenu(hwnd, 0)

If hMenu Then
menuItemCount = GetMenuItemCount(hMenu)
RemoveMenu hMenu, _
menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION
DrawMenuBar hwnd
End If

End Sub


In the UserForm code have this:

Private Sub UserForm_Activate()
DisableCloseButton GetActiveWindow()
End Sub

You will need some sort of control on the form to unload it:

Private Sub CommandButton1_Click()
Unload Me
End Sub


RBS


"NateBuckley" wrote in message
...
Hello I'm just wondering if anyone can help me with the following
question:

I have multiple user forms for which on some I wish to remove the X button
at the top that closes the form. I'm guessing I'll have to use the windows
API for this? I've only just started learning the fundementals of Windows
API
Calls, and thus I'm a little stuck.

I'm just wondering what I would have to do, to do this, my user form's
name
is "frm_Mod_Gen_CEmp"

Thanks in advance for any help.