vb任务栏图标右键菜单
'窗体无边框,加半透明
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
'任务栏图标
Option Explicit
Const MAX_TOOLTIP As Integer = 64
Const NIF_ICON = &H2 '删除图标
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4
Const NIM_ADD = &H0 '添加图标到任务栏提示区
Const NIM_DELETE = &H2
Const WM_MOUSEMOVE = &H200
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDBLCLK = &H203
Const WM_RBUTTONDOWN = &H204
RBUTTONUP = &H205 Const WM_
Const WM_RBUTTONDBLCLK = &H206
Const SW_RESTORE = 9
Const SW_HIDE = 0
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private nfIconData As NOTIFYICONDATA
Private Sub Form_Load()
Dim sy As Long
Dim newsy As Long
Const GWL_STYLE = -16
Const WS_CAPTION = &HC00000
Const WS_BORDER = &H800000
sy = GetWindowLong(Me.hwnd, GWL_STYLE)
newsy = SetWindowLong(Me.hwnd, GWL_STYLE, sy - WS_CAPTION - WS_BORDER)
sy = GetWindowLong(Form3.hwnd, GWL_STYLE)
newsy = SetWindowLong(Form3.hwnd, GWL_STYLE, sy - WS_CAPTION - WS_BORDER)
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE '窗体置顶
SetWindowPos Form3.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE '窗体置顶
nfIconData.hwnd = Me.hwnd
nfIconData.uID = Me.Icon
nfIconData.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
nfIconData.uCallbackMessage = WM_MOUSEMOVE
nfIconData.hIcon = Me.Icon.Handle
nfIconData.szTip = "专家指导" & vbNullChar
nfIconData.cbSize = Len(nfIconData)
Call Shell_NotifyIcon(NIM_ADD, nfIconData)
Timer1.Interval = 10
Timer1.Enabled = True
Form3.Show
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
If lMsg = WM_LBUTTONDBLCLK Then
Me.Show
Form3.Show
End If
End Sub
Private Sub Image1_DblClick()
flg(num) = 0
End Sub
'右键菜单
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then
Form2.PopupMenu mnufile, 0, X, Y
End If
'Form2.hide
'Form3.Text1.Text = "1234tfdszxcvgtrdc"
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0& End Sub