Remove Close Icon ?

  • Thread starter Thread starter Malcolm
  • Start date Start date
M

Malcolm

Hi All

I'd like to remove the close icon on the titel bar and
control the close myself. I can close everything OK but
cannot find a way to remove the X from the title bar.
I am including a button that pops up with an
'You are about to close this application Are You Sure ?'

I can do everything except remove the X

Any ideas please ?

Malcolm
 
Alas, you can't remove the 'x'....om my wish list too..

Patrick Molloy
Microsoft Excel MVP
 
Thanks - wrong answer !!!

Is there a way to trap it without closing the window ?

UserForm_Terminate is too late !
 
You could of course remove the caption bar completely. Three parts to it,
the windows declarations, the procedure to hide the bar and finally calling
it from the from initalize event section.

Cheers
N

Using the following code.

FIRST: Put the following in the form declarations section

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

SECOND: Put the following procedure in the form

Private Function HideCaptionBar()
Dim lngHnd As Long
Dim lngStyle As Long
Dim lngH(1) As Long
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000
lngH(0) = Me.Height - Me.InsideHeight
If Val(Application.Version) > 8 Then
lngHnd = FindWindow("ThunderDFrame", Me.Caption)
Else
lngHnd = FindWindow("ThunderXFrame", Me.Caption)
End If
lngStyle = GetWindowLong(lngHnd, GWL_STYLE) And Not WS_CAPTION
SetWindowLong lngHnd, GWL_STYLE, lngStyle
DrawMenuBar lngHnd
lngH(1) = Me.Height - Me.InsideHeight
Me.Height = Me.Height + lngH(1) - lngH(0)
End Function


THIRD: In the form initialize section put the additional call instruction

Private Sub UserForm_Initialize()

Call HideCaptionBar

End Sub
 
Malcolm -

You can use UserForm_QueryClose to see how the form was told to close:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'' Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the Close button does not work.", vbInformation
Cancel = True
End If
End Sub

- Jon
 
thx Jon,

I ended up finding it the hard way but you are dead right -
it does exactly what I want and I can now prohibit the
close from the close button !
 
Back
Top