如何做一个没有控制栏(BorderStyle=0),的右键菜单。

cow_boys 2003-12-23 12:08:00
当窗体有菜单后,控制栏(标题栏)就出现了,虽然BorderStyle=0。
如何做出一个没有标题栏的有菜单的窗体。
...全文
18 点赞 收藏 12
写回复
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
quanquan626 2004-01-02
聆听
回复
809982 2004-01-02
聆听
回复
cow_boys 2004-01-02
ding
回复
danielinbiti 2003-12-23
可以专门建一个窗体做右键菜单窗体。
回复
lihonggen0 2003-12-23

窗体的BorderStyle设为2

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
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000

Private Sub Form_Load()

Dim L As Long
L = GetWindowLong(Me.hWnd, GWL_STYLE)
L = L And Not (WS_CAPTION)
L = SetWindowLong(Me.hWnd, GWL_STYLE, L)
Me.Move Me.Left, Me.Top, Me.Width, Me.Height - 10
End Sub

回复
lihonggen0 2003-12-23
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
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000

Private Sub Form_Load()

Dim L As Long
L = GetWindowLong(Me.hWnd, GWL_STYLE)
L = L And Not (WS_CAPTION)
L = SetWindowLong(Me.hWnd, GWL_STYLE, L)
Me.Move Me.Left, Me.Top, Me.Width, Me.Height - 10
End Sub


回复
rainstormmaster 2003-12-23
先把窗体的BorderStyle设为2,添加菜单,然后用setwindowlong改变窗体风格:
Option Explicit

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 Const GWL_STYLE = (-16)
Private Const WS_SYSMENU = &H80000
Private Const WS_CAPTION = &HC00000
Private Const WS_SIZEBOX = &H40000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
'为窗体指定一个新位置和状态函数
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
Private Const SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOREPOSITION = &H200
'获得整个窗体的大小和位置
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type



Private Sub Form_Load()
Dim lStyle As Long
Dim MyRect As RECT
Dim Change As Boolean
'获取窗体的大小和位置
GetWindowRect Me.hwnd, MyRect
'取得当前窗体信息
lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_CAPTION
lStyle = lStyle And Not WS_SIZEBOX
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
'按lStyle的值设置窗体信息
SetWindowLong Me.hwnd, GWL_STYLE, lStyle
'保持窗体的大小与位置不变
SetWindowPos Me.hwnd, 0, MyRect.Left, MyRect.Top, MyRect.Right - MyRect.Left, MyRect.Bottom - MyRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED

End Sub


回复
jhzhou882 2003-12-23
我觉得基本上很难
回复
lirh 2003-12-23
mark
回复
pcwak 2003-12-23
关注
回复
flc 2003-12-23
关注
回复
cow_boys 2003-12-23
to danielinbiti(金)

那不是要常加载那个窗体吗。
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7450

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告