
August 17th, 2003, 11:23 AM
|
|
Average Intelligence
|
|
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678
Time spent in forums: 10 m 22 sec
Reputation Power: 6
|
|
Code:
Disable the close button from a form
Disable the Close button on any form in your project with this handy code snippet!
First of all, you will need to add a module to your project. (Project->Add Module).
Into this module, paste the following code:
Public Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const MF_BYPOSITION = &H400&
Public Declare Function RemoveMenu Lib "User32" (ByVal hMenu As Long, _
ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function GetSystemMenu Lib "User32" (ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Public Sub DisableClose(hWnd As Long)
Dim hMenu As Long
hMenu = GetSystemMenu(hWnd, 0)
RemoveMenu hMenu, 6, MF_BYPOSITION
RemoveMenu hMenu, 5, MF_BYPOSITION
End Sub
Then, to disable the Close button on a form, use
DisableClose(form.hWnd)
e.g.
DisableClose(Me.hWnd)
will disable the close button from the current form.
|