在VB中,如何让自己的窗体最小化化像QQ一样最小化到托盘区去,而不是在任务栏上?

 我来答
匿名用户
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
匿名用户
2013-09-09
展开全部
原则上我也不太会,但是我帮你找到解决方案了 http://zhidao.baidu.com/question/10939984.html
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式