Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1Dim nidIcon As NOTIFYICONDATAPrivate Sub Command1_Click()
'添加
Shell_NotifyIcon NIM_ADD, nidIcon
End SubPrivate Sub Command2_Click()
'删除
Shell_NotifyIcon NIM_DELETE, nidIcon
End SubPrivate Sub Form_Load()
With nidIcon
.cbSize = Len(nidIcon)
.hIcon = Me.Icon
.hwnd = Me.hwnd
.szTip = "Sample" & Chr(0)
.uCallbackMessage = 0
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
End With
End Sub
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1Dim nidIcon As NOTIFYICONDATAPrivate Sub Command1_Click()
'添加
Shell_NotifyIcon NIM_ADD, nidIcon
End SubPrivate Sub Command2_Click()
'删除
Shell_NotifyIcon NIM_DELETE, nidIcon
End SubPrivate Sub Form_Load()
With nidIcon
.cbSize = Len(nidIcon)
.hIcon = Me.Icon
.hwnd = Me.hwnd
.szTip = "Sample" & Chr(0)
.uCallbackMessage = 0
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
End With
End Sub
解决方案 »
- 报表打印 脚注问题
- GetOpenFilename方法如何设定打开文件目录
- 请各位大侠帮帮吗?!我是初学者!!!!!!!!!!!!
- 有谁知道在哪里可以下载清华刘炳文编写的《Visual Basic程序设计教程》的word或Powerpoint讲稿?
- 如何使用DataGrid+ADO显示查询的记录集RS中的内容
- 请问大侠们关于VB的一个中文问题
- 散分,有谁知道《传奇》《反恐》《帝国》《三角》《星际》是用什么工具编的
- ………………请大家给我推荐一两个支持中文和图片的控件,马上给分…………
- vb6.0 msdn
- To Iamfish 1
- VB创建多线程真的不安全吗?那位大哥有代码,小弟一定加分.
- 关于rst.Filter的问题
'Declare a user-defined variable to pass to the Shell_NotifyIcon
'function.
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type 'Declare the constants for the API function. These constants can be
'found in the header file Shellapi.h. 'The following constants are the messages sent to the
'Shell_NotifyIcon function to add, modify, or delete an icon from the
'taskbar status area.
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2 'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status
'area.
Private Const WM_MOUSEMOVE = &H200 'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4 'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area. 'Left-click constants.
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up 'Right-click constants.
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up 'Declare the API function call.
Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean 'Dimension a variable as the user-defined data type.
Dim nid As NOTIFYICONDATA Private Sub Command1_Click()
'Click this button to add an icon to the taskbar status area. 'Set the individual values of the NOTIFYICONDATA data type.
nid.cbSize = Len(nid)
nid.hWnd = Form1.hWnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Form1.Icon
nid.szTip = "Taskbar Status Area Sample Program" & vbNullChar 'Call the Shell_NotifyIcon function to add the icon to the taskbar
'status area.
Shell_NotifyIcon NIM_ADD, nid
End Sub Private Sub Command2_Click()
'Click this button to delete the added icon from the taskbar
'status area by calling the Shell_NotifyIcon function.
Shell_NotifyIcon NIM_DELETE, nid
End Sub Private Sub Form_Load()
'Set the captions of the command button when the form loads.
Command1.Caption = "Add an Icon"
Command2.Caption = "Delete Icon"
End Sub Private Sub Form_Terminate()
'Delete the added icon from the taskbar status area when the
'program ends.
Shell_NotifyIcon NIM_DELETE, nid
End Sub Private Sub Form_MouseMove _
(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
'Event occurs when the mouse pointer is within the rectangular
'boundaries of the icon in the taskbar status area.
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
CommonDialog1.DialogTitle = "Select an Icon"
sFilter = "Icon Files (*.ico)|*.ico"
sFilter = sFilter & "|All Files (*.*)|*.*"
CommonDialog1.Filter = sFilter
CommonDialog1.ShowOpen
If CommonDialog1.filename <> "" Then
Form1.Icon = LoadPicture(CommonDialog1.filename)
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONDOWN
Dim ToolTipString As String
ToolTipString = InputBox("Enter the new ToolTip:", _
"Change ToolTip")
If ToolTipString <> "" Then
nid.szTip = ToolTipString & vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK
End Select
End Sub4、Press the F5 key to run the project or on the Tools menu, click Run Project. Click Add Icon to add an icon to the taskbar status area. Double-click the icon to change the icon. Right-click the icon to change the ToolTip string. Click Delete Icon to remove the icon from the taskbar status area. 这是MSDN上面的例子,你不妨看看
把楼上那位的代码:
.uCallbackMessage = 0
改为:
.uCallbackMessage = WM_LBUTTONUP
或者:
.uCallbackMessage = WM_RBUTTONUP
就可以回调了。
在Form_MouseMove事件中对加上这样的代码:
Me.WindowState=2就可以放大程序了。
双击可以做到的呀
我是想达到瑞星防火墙哪样,当点击add_icon按钮时程序本身在桌面不可见,当双击任务栏上的这一个图标是,程序又可见。而你这一段代码还需要修改一点吧?
1、我想点击隐藏时form1.visuble=false;任务栏出现图标。
2、当双击任务栏上的这一个图标是form1.visuble=true;
3、当右键在任务栏上的这个图标上点击时弹出一个菜单,可以退出程序,任务栏的图标消失。
4、当退出程序时任务栏的图示消失。
1、我想点击隐藏时form1.visuble=false;任务栏出现图标。
2、当双击任务栏上的这一个图标是form1.visuble=true;
3、当右键在任务栏上的这个图标上点击时弹出一个菜单,可以退出程序,任务栏的图标消失。
4、当退出程序时任务栏的图示消失。
主要是: 1、在双击任务栏图标事件中添加一条语句,即:form1.visible=true;
2、在右键点击任务栏图标事件中添加一条语句:popmenu...
但具体怎么添加呢,请大侠帮忙。
email:[email protected]
‘添加模块:
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean'在Form里Dim t As NOTIFYICONDATA '托盘装载图标参数结构Dim Form_Flag As Boolean '窗口是否已经显示
'显示图标
Private Sub Load_Ico()
t.cbSize = Len(t)
t.hWnd = Me.hWnd
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
t.ucallbackMessage = WM_MOUSEMOVE
t.hIcon = Me.Icon
t.szTip = FrmCaption & Chr$(0)
Shell_NotifyIcon NIM_ADD, t
End Sub'卸载图标
Private Sub UnLoad_Ico()
t.cbSize = Len(t)
t.hWnd = Me.hWnd
t.uId = 1&
Shell_NotifyIcon NIM_DELETE, t
End Sub'鼠标在图标上双击事件
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case CLng(X)
Case WM_LBUTTONDBLCLK
If Form_Flag Then
Hide_Form
Else
Show_Form
End If
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_RBUTTONDBLCLK
Case WM_RBUTTONDOWN
Me.PopupMenu nnn
Case WM_RBUTTONUP
End Select
End Sub'显示窗口
Private Sub Show_Form()
'使激活
'ForceForegroundWindow Me.hWnd '此函数你先别用,如果这段代码调试通过,我再给你这个函数的具体代码,其作用是在你双击图标时,窗口显示为激活窗口
Me.Show
Me.WindowState = 0
Form_Flag = True
End Sub'隐藏窗口
Private Sub Hide_Form()
If Me.WindowState <> 1 Then
Me.WindowState = 1
End If
Me.Hide
Form_Flag = False
End Sub