在论坛上,看到的代码多是去除窗体的标题栏、关闭按钮,现在有一个问题想请教大家:如何去除窗体四周的边框(即窗体没有边框)?
以下的代码不能实现去除窗体的边框的功能:
Private Declare Function DrawMenuBar Lib "user32" (ByVal Hwnd 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 SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_BORDER = &H800000 '窗口带有一个薄边框
Private Const WS_DLGFRAME = &H400000 '带有一般对话框的风格,但没有标题栏
Private Const WS_CAPTION = &HC00000 '窗口带有一个标题栏,经测试,实际上等于 (WS_BORDER Or WS_DLGFRAME)
Private Const WS_SIZEBOX = &H40000 '窗口带有一个可以调整窗口大小的边框(即VB里的Sizable,其他地方的边框均指不具调整大小功能的边框)
Private Const WS_THICKFRAME = &H40000
Private Const WS_MAXIMIZEBOX = &H10000 '窗口带有最大化按钮,该窗口必须具有 WS_CAPTION 风格
Private Const WS_MINIMIZEBOX = &H20000 '窗口带有最小化按钮,该窗口必须具有 WS_CAPTION 风格
Private Const WS_SYSMENU = &H80000 '在窗口的标题栏上增加一个系统菜单,该窗口必须具有 WS_CAPTION 风格(即WS_BORDER和WS_DLGFRAME)
Private Const WS_HSCROLL = &H100000 '窗口带有一个水平滚动条
Private Const WS_VSCROLL = &H200000 '窗口带有一个垂直滚动条
Private Const WS_OVERLAPPED = &H0& '窗口是一个交迭式窗口。交迭式窗口带有一个标题栏和一个边框
Private Const WS_TILED = &H0& '窗口是一个交迭式窗口。交迭式窗口带有一个标题栏和一个边框
Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX) _
'窗口是一个交迭式窗口,并且组合了 WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU,WS_THICKFRAME, WS_MINIMIZEBOX 以及 WS_MAXIMIZEBOX 这些风格
Private Const WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
Private Sub UserForm_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim IStyle As Long, Hwnd As Long
If Val(Application.Version) < 9 Then
Hwnd = FindWindow("ThunderXFrame", Me.Caption) '获取窗口句柄
Else
Hwnd = FindWindow("ThunderDFrame", Me.Caption) '获取窗口句柄
End If
IStyle = GetWindowLong(Hwnd, GWL_STYLE)
' IStyle = IStyle And WS_CAPTION
SetWindowLong Hwnd, GWL_STYLE, IStyle And Not WS_OVERLAPPEDWINDOW
DrawMenuBar Hwnd
End Sub
在VB中,用 SetWindowLong Hwnd, GWL_STYLE, IStyle And Not WS_OVERLAPPEDWINDOW 是可以实现没有边框的窗体的。
arb2gY5J.rar
(136.97 KB, 下载次数: 474)
[此贴子已经被作者于2005-11-3 9:41:28编辑过] |