Jean-Guy
Wed Feb 15 16:27:15 CST 2006
Jonathan West was telling us:
Jonathan West nous racontait que :
> "Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
> news:uKI7RwmMGHA.2276@TK2MSFTNGP15.phx.gbl...
>
>>>
>>> You can disable the X, using similar techniques as for disabling the
>>> X in a UserForm, there are just different techniques needed for
>>> identifying the window handle for that document window.
>>
>> I meant through VBA...
>> Do you mean that there is a VBA way of doing this?
>> I thought it was only possible through somewhat complicated API
>> calls.
>
> Depends what you think of as complicated. Most of the code in this
> article can be used
>
> How to disable the X close button on a UserForm
>
http://word.mvps.org/FAQs/Userforms/DisableClose.htm
>
Duh!
Must be a slow day!
Right you are, so the following, by using API stuff from VBA will dim the X
on the Word application Window:
'_______________________________________
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
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 Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private hWnd As Long
'_______________________________________
Sub DisableXinWordWindow()
Dim hMenu As Long
Dim menuItemCount As Long
Dim MyWinCaption As String
MyWinCaption = ActiveWindow.Caption & " - " & Application.Caption
'Obtain the window handle to the userform
hWnd = FindWindow(vbNullString, MyWinCaption)
'Obtain the handle to the form's system menu
hMenu = GetSystemMenu(hWnd, 0)
If hMenu Then
'Obtain the number of items in the menu
menuItemCount = GetMenuItemCount(hMenu)
'Remove the system menu Close menu item.
'The menu item is 0-based, so the last
'item on the menu is menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_REMOVE Or MF_BYPOSITION)
'Remove the system menu separator line
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_REMOVE Or MF_BYPOSITION)
'Force a redraw of the menu. This
'refreshes the titlebar, dimming the X
Call DrawMenuBar(hWnd)
End If
End Sub
'_______________________________________
But, as you said, that by itself is useless.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site:
http://www.word.mvps.org