设置窗体菜单的函数(收集+修改)
已有 999 次阅读2008-1-27 15:06
Option Compare Database
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
'在CLOSE 事件中使用X = unloadmenux("XX1")
Public Function unloadmenux(ByVal 自定义的菜单名 As String) As Boolean
Application.CommandBars(自定义的菜单名).Visible = False
unloadmenux = True
End Function
'在窗体的LOAD事件中使用X = loadmenux("XX1", Me.Hwnd)
Public Function loadmenux(ByVal 自定义的菜单名 As String, ByVal 窗体的句柄 As Long) As Boolean
With Application.CommandBars(自定义的菜单名)
.Top = -18
.Left = -2
.Position = 4
.Protection = 6
.Visible = True
End With
SetParent FindWindow(vbNullString, 自定义的菜单名), 窗体的句柄
loadmenux = True
End Function
'在当前的鼠标指针XY坐标处弹出菜单
Public Function loadpopmenu(ByVal 自定义弹出菜单名 As String) As Boolean
Dim z As POINTAPI
GetCursorPos z
CommandBars(自定义弹出菜单名).ShowPopup z.X, z.Y
End Function