VBA自訂表單右上角的關閉[X]能否隱藏

小舖文 http://www.blueshop.com.tw/board/FUM200501271723350KG/BRD201209201920598C0.html




--------------------------------------------------------------------------------------------------

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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WS_SYSMENU = &H80000
Private Const GWL_STYLE = (-16)


Private Sub UserForm_Initialize()
    Dim lStyle As Long
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, Me.Caption)
    lStyle = GetWindowLong(hwnd, GWL_STYLE)
    lStyle = lStyle And Not WS_SYSMENU
    SetWindowLong hwnd, GWL_STYLE, lStyle
End Sub

沒有留言:

張貼留言