Tuesday, April 19, 2011

How to disable the Restore button a MDI form in VB 6?


Use in Modual :

Private Const WS_THICKFRAME As Long = &H40000
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 SetWindowPos Lib _
"user32" (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


'------------------------------------------------------------

Function DisableResBtn(frm As Form)
Const WS_THICKFRAME = &H40000
Const WS_MAXIMIZE = &H1000000
Const WS_MAXIMIZEBOX = &H10000
Const GWL_STYLE = (-16)
Const SWP_FRAMECHANGED = &H20
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
'Const HWND_TOP = 0

Dim nStyle As Long
Dim hwnd As Long
nStyle = GetWindowLong(frm.hwnd, GWL_STYLE)
nStyle = nStyle And Not (WS_THICKFRAME)
nStyle = nStyle And Not (WS_MAXIMIZE)
nStyle = nStyle And Not (WS_MAXIMIZEBOX)
Call SetWindowLong(frm.hwnd, GWL_STYLE, nStyle)
SetWindowPos frm.hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER

End Function
'------------------------------------------------------------------------
 

' This code use in MDI Form for Load Event

Private Sub MDIForm_Load()
  Call DisableResBtn(Me)
End Sub



No comments:

Post a Comment