VB 如何让窗体既没有标题栏,又可以在任务栏中显示标题图标等。

2024年11月23日 00:09
有1个网友回答
网友(1):

'怎么不解决呢?虽然显示了,但没有常见的右键菜单以及菜单功能,解决一下
'添加一个模块,加入以下代码
Option Explicit
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetWindowLong Lib "user32"升悔 Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const WM_CLOSE = &H10
Private Const SC_CLOSE = &HF060&
Public lOldproc As Long
'处理一些消息
Public Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_SYSCOMMAND
'使无边框窗体系统菜单的关闭按钮有效
If wParam = SC_CLOSE Then
SendMessage hWnd, WM_CLOSE, ByVal 0&, ByVal 0&
End If
End Select

WndProc = CallWindowProc(lOldproc, hWnd, Msg, wParam, lParam)
End Function
'移动无边框窗体,可滑笑行用于任意控件的鼠标按信哗下事件里
Public Sub DragForm(Frm As Form)
ReleaseCapture
Call SendMessage(Frm.hWnd, WM_NCLBUTTONDOWN, 2, 0&)
End Sub

'窗体加载事件
'使无边框窗体获得系统菜单
Private Sub Form_Load()
Dim lStyle&
lStyle = GetWindowLong(Me.hWnd, -16)
lStyle = lStyle Or &H80000 Or &H20000
SetWindowLong Me.hWnd, -16, lStyle
lOldproc = SetWindowLong(Me.hWnd, -4, AddressOf WndProc)
End Sub