在VB中,如何让自己的窗体最小化化像QQ一样最小化到托盘区去,而不是在任务栏上?
2个回答
2013-09-09
展开全部
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias " Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
注意:上面这个API函数在XP中没有别名,将别名去掉后为:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll"(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
3:声明7个常数:
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
4:定义1个NOTIFYICONDATA类型
Public Type NOTIFYICONDATA
cbSize as Long
hWnd as Long
uId as Long
uFlags as Long
uCallBackMessage as Long
hIcon as Long
szTip as String
End Type
5:声明一个nid的类型
Public nid as NOTIFYICONDATA
思路清晰后,开始编写代码
1:在窗体中画1个Command,它的Caption属性为:"最小化"
2:将窗体Form的MinButton的属性设为:"False"
3:在窗体中添加1个模块,模块中的代码为:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll"(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Type NOTIFYICONDATA
cbSize as Long
hWnd as Long
uId as Long
uFlags as Long
uCallBackMessage as Long
hIcon as Long
szTip as String
End Type
Public nid as NOTIFYICONDATA
4:编写Command的单击事件:
Private Sub Command1_Click()
nid.cbSize = Len(nid)
nid.uId = vbNull
nid.hWnd = Me.hWnd
nid.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon
nid.szTip = "窗体最小化"
Shell_NotifyIcon NIM_ADD, nid
Me.Hide
End Sub
5:编写窗体的MouseMove事件:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
msg = X / 15
If msg = WM_LBUTTONDBLCLK Then
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
End If
End Sub
注意:上面这个API函数在XP中没有别名,将别名去掉后为:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll"(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
3:声明7个常数:
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
4:定义1个NOTIFYICONDATA类型
Public Type NOTIFYICONDATA
cbSize as Long
hWnd as Long
uId as Long
uFlags as Long
uCallBackMessage as Long
hIcon as Long
szTip as String
End Type
5:声明一个nid的类型
Public nid as NOTIFYICONDATA
思路清晰后,开始编写代码
1:在窗体中画1个Command,它的Caption属性为:"最小化"
2:将窗体Form的MinButton的属性设为:"False"
3:在窗体中添加1个模块,模块中的代码为:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll"(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Type NOTIFYICONDATA
cbSize as Long
hWnd as Long
uId as Long
uFlags as Long
uCallBackMessage as Long
hIcon as Long
szTip as String
End Type
Public nid as NOTIFYICONDATA
4:编写Command的单击事件:
Private Sub Command1_Click()
nid.cbSize = Len(nid)
nid.uId = vbNull
nid.hWnd = Me.hWnd
nid.uFlags = NIF_TIP Or NIF_MESSAGE Or NIF_ICON
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon
nid.szTip = "窗体最小化"
Shell_NotifyIcon NIM_ADD, nid
Me.Hide
End Sub
5:编写窗体的MouseMove事件:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
msg = X / 15
If msg = WM_LBUTTONDBLCLK Then
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
End If
End Sub
2013-09-09
展开全部
原则上我也不太会,但是我帮你找到解决方案了 http://zhidao.baidu.com/question/10939984.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询