| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1190 人关注过本帖
标题:关于MDI窗口托盘的问题
只看楼主 加入收藏
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
结帖率:78.95%
收藏
已结贴  问题点数:20 回复次数:15 
关于MDI窗口托盘的问题
我想实现MDI窗口的托盘,普通FORM托盘的代码不适合使用。
盼各位分享一下代码,跪谢(如有托盘闪烁的更好)
搜索更多相关主题的帖子: 托盘 
2015-04-23 15:05
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
这种求助帖就那么不受人待见吗?
2015-04-27 08:52
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:20 
回复 2楼 linandceline
实现MDI窗口托盘的意思是右下角只出现子窗口图标,而父窗口图标不显示?
“不受人待见”可能是因为大家各有各的事干,也可能因为情况比较特殊,可能性太多了。
把鼠标移动代码改为
Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
其它不变
...
模块
程序代码:
Public 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
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 = &H4
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up

Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
MDI窗体
程序代码:
Dim nid As NOTIFYICONDATA ' trayicon variable

Sub minimize_to_tray()
Me.Hide
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon ' the icon will be your Form1 project icon
nid.szTip = "blablabla text u want to show when mouse over tray iicon" & vbNullChar
Shell_NotifyIcon NIM_ADD, nid
End Sub

Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Me.Show ' show form
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Case WM_RBUTTONDOWN
Case WM_RBUTTONUP
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
Case WM_RBUTTONDBLCLK
End Select

End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
End Sub

Private Sub minimize_Click()
minimize_to_tray
End Sub
自己按需修改调整




[ 本帖最后由 lianyicq 于 2015-4-27 10:14 编辑 ]

大开眼界
2015-04-27 09:40
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
多谢,我马上去试下
另外,下面这段,用RESIZE判断的话效果有没有区别?

以下是引用lianyicq在2015-4-27 09:40:22的发言:
Private Sub minimize_Click()
minimize_to_tray
End Sub
自己按需修改调整
2015-04-27 10:50
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
我调整了之后放入,同时加入了托盘的右键菜单:显示窗口和退出
但是显示窗口点击时要点击两次才能反应,这是什么原因?

Dim nid As NOTIFYICONDATA ' trayicon variable
Sub minimize_to_tray()
Me.Hide
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon ' the icon will be your Form1 project icon
nid.szTip = "处理平台" & vbNullChar
Shell_NotifyIcon NIM_ADD, nid
End Sub
Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Case WM_RBUTTONDOWN
Case WM_RBUTTONUP
  Me.PopupMenu Pomenu
Case WM_RBUTTONDBLCLK
End Select

End Sub
Private Sub MDIForm_Resize()
  If Me.WindowState = vbMinimized Then
    minimize_to_tray
  Else
    Shell_NotifyIcon NIM_DELETE, nid
  End If
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
End Sub
Private Sub MDIForm_Load()
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
End Sub

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Shell_NotifyIcon NIM_DELETE, nid ' del tray icon
Unload Me
End Sub

Private Sub showw_click()
  Me.Show
  Me.WindowState = vbNormal
End Sub
Private Sub quitp_click()
Unload Me
End Sub

[ 本帖最后由 linandceline 于 2015-4-30 13:45 编辑 ]
2015-04-30 09:41
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:0 
回复 5楼 linandceline
定义一个变量
Dim MiniStatus As Boolean

Sub minimize_to_tray()
...
MiniStatus = True
End Sub

Private Sub maxmize_Click()
...
MiniStatus = False
End Sub

Private Sub MDIForm_Resize()
  If Me.WindowState = vbMinimized And MiniStatus = False Then
    minimize_to_tray
...
End Sub

大开眼界
2015-04-30 10:22
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
OK,解决。
能说明一下原因么?
2015-04-30 14:16
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
又有个问题出现。我在未最小化时用鼠标在窗口内部晃动一下,结果出现菜单了
毫无解决头绪,求助。
图片附件: 游客没有浏览图片的权限,请 登录注册
2015-05-14 10:10
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:0 
回复 8楼 linandceline
出现菜单是执行popupmenu?检查一下为什么会执行到这一句

大开眼界
2015-05-14 10:27
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
就是下面这部分语句,而且我试过了,无论Me.PopupMenu Pomenu放到哪个条件,晃动鼠标还是会出现菜单
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Case WM_RBUTTONDOWN
Case WM_RBUTTONUP
  Me.PopupMenu Pomenu
Case WM_RBUTTONDBLCLK
End Select
2015-05-14 10:45
快速回复:关于MDI窗口托盘的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029774 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved