标题:关于MDI窗口托盘的问题
只看楼主
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
我刚换了语句,试了下还未发现问题
    If Button = 2 Then
        Me.PopupMenu Pomenu
    End If
2015-05-14 10:50
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:735
专家分:3478
注 册:2013-1-26
得分:0 
回复 10楼 linandceline
是这样,代码是用
    Select Case msg
来检测鼠标按键。有可能会造成非鼠标点击的msg和WM_RBUTTONUP相等,产生误动作。
改下代码试试,同上次一样增加状态检测。
程序代码:
  If MiniStatus = True Then
    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
        PopupMenu normal
'Me.Show
'Shell_NotifyIcon NIM_DELETE, nid
      Case WM_RBUTTONDBLCLK
    End Select
  End If


大开眼界
2015-05-14 10:52
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
回复 12楼 lianyicq
不好意思啊,还是要弱弱问一句,这样会不会比较复杂了?
直接用BOTTON值会不会更好?有弊病么?
2015-05-14 10:58
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:735
专家分:3478
注 册:2013-1-26
得分:0 
回复 13楼 linandceline
你试试在最大化时,按住鼠标移动,如果不加状态检测,仍会出现菜单。
注意是在mousemove中检测鼠标操作,除了按下左、中、右三键没有第四种状态。
但现在代码在mousemove中能处理按下、释放、单击、双击,这就是区别,更深入的需要了解Shell_NotifyIcon 这个API的使用原理。

大开眼界
2015-05-14 11:46
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
恩,这个我试过了,不加检测的确是会出现菜单
多谢耐心指教
2015-05-14 11:53
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
我又在网上找了一些例子,同时加入了闪烁图标,代码在下面列出来
问题有2
1、MDI窗口如果在最小化前有子窗口活跃中,那么最小化后托盘图标点击不了(所以在RESIZE里有UNLOAD的代码出现)
2、托盘图标仍然需要点击两次才可以恢复窗口(而状态判定检测Formministatus是已经加入了的)


------MDIFORM代码------
Dim appli As Integer
Dim a As Integer
Dim Formministatus As Boolean
Private Sub MDIForm_MouseMove(Button As Integer, Shift As Integer, X As Single, y As Single)
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX

If Me.WindowState = vbMinimized And Formministatus = True Then
  Select Case lMsg
    Case LeftUp
      Me.Show
      Me.WindowState = vbMaximized
    Case RightUp
      PopupMenu Pomenu
  End Select
End If
End Sub

Private Sub MDIForm_Resize()
If Me.WindowState = vbMinimized Then
  Unload Form1
  Unload Form11
  Unload Form2
  Unload Form21
  Unload Form22
  Unload Form3
  Unload Form9
  If appli = 0 Then
    MsgBox "已最小化窗体,请点击恢复", vbOKOnly + vbInformation, "提示"
    appli = 1
  End If
  Me.Hide
  TrayAddIcon Me, "处理平台"
  Formministatus = True
  Timer1.Enabled = True
  Timer1.Interval = 500
Else
  Timer1.Enabled = False
  Formministatus = False
  TrayRemoveIcon
End If
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
TrayRemoveIcon
End Sub

Private Sub MDIForm_Load()
Me.Icon = Picture1(0).Picture
Dim m As String
m = Environ("USERNAME")
MDIForm1.Caption = "处理平台" & "      " & m
Load Form9
Me.SetFocus
End Sub

Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
TrayRemoveIcon
Unload Me
End Sub

Private Sub Timer1_Timer()
If a = 0 Then
  Me.Icon = Picture1(0).Picture
  a = a + 1
Else
  Me.Icon = Picture1(1).Picture
  a = 0
End If
TraychangeIcon
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim m As String
m = Environ("USERNAME")
  Select Case (Button.Index)
    Case 1
         Me.PopupMenu Addnew
    Case 2
          Me.PopupMenu Settle
    Case 3
        Me.PopupMenu Findout
    Case 4
      Unload Me
  End Select
End Sub

Private Sub showw_click()
  Me.Show
  Me.WindowState = vbMaximized
End Sub

Private Sub quitp_click()
TrayRemoveIcon
Unload Me
End Sub

------MODULE代码------
Option Explicit

Private Const LR_LOADFROMFILE = &H10
Private Const LR_LOADMAP3DCOLORS = &H1000
Private Const IMAGE_ICON = 1
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const NIF_STATE = &H8
Private Const NIF_INFO = &H10
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIM_SETFOCUS = &H3
Private Const NIM_SETVERSION = &H4
Private Const NIM_VERSION = &H5
Private Const WM_USER As Long = &H400
Private Const NIN_BALLOONSHOW = (WM_USER + 2)
Private Const NIN_BALLOONHIDE = (WM_USER + 3)
Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)
Private Const NOTIFYICON_VERSION = 3
Private Const NIS_HIDDEN = &H1
Private Const NIS_SHAREDICON = &H2
Private Const WM_NOTIFY As Long = &H4E
Private Const WM_COMMAND As Long = &H111
Private Const WM_CLOSE As Long = &H10
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Const WM_LBUTTONDBLCLK As Long = &H203
Private Const WM_MBUTTONDOWN As Long = &H207
Private Const WM_MBUTTONUP As Long = &H208
Private Const WM_MBUTTONDBLCLK As Long = &H209
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_RBUTTONDBLCLK As Long = &H206

Public Enum bFlag
    NIIF_NONE = &H0
    NIIF_INFO = &H1
    NIIF_WARNING = &H2
    NIIF_ERROR = &H3
    NIIF_GUID = &H5
    NIIF_ICON_MASK = &HF
    NIIF_NOSOUND = &H10
End Enum

Private Type NOTIFYICONDATA
    cbSize As Long
    hWnd As Long
    uID As Long
    uFlags As Long
    uCallbackMessage As Long
    hIcon As Long
    szTip As String * 128
    dwState As Long
    dwStateMask As Long
    szInfo As String * 256
    uTimeoutAndVersion As Long
    szInfoTitle As String * 64
    dwInfoFlags As Long
End Type

Public Enum TrayRetunEventEnum
    MouseMove = &H200
    LeftUp = &H202
    LeftDown = &H201
    LeftDbClick = &H203
    RightUp = &H205
    RightDown = &H204
    RightDbClick = &H206
    MiddleUp = &H208
    MiddleDown = &H207
    MiddleDbClick = &H209
    BalloonClick = (WM_USER + 5)
End Enum

Public ni As NOTIFYICONDATA
Public Sub TrayAddIcon(ByVal MyForm As Form, ByVal ToolTip As String, Optional ByVal bFlag As bFlag)
    With ni
        .cbSize = Len(ni)
        .hWnd = MDIForm1.hWnd
        .uID = vbNull
        .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        .uCallbackMessage = WM_MOUSEMOVE
        .hIcon = MDIForm1.Icon
        .szTip = ToolTip & vbNullChar
    End With
    Shell_NotifyIcon NIM_ADD, ni
End Sub

Public Sub TraychangeIcon()
    With ni
        .hIcon = MDIForm1.Icon
    End With
    Shell_NotifyIcon NIM_MODIFY, ni
End Sub

Public Sub TrayRemoveIcon()
    Shell_NotifyIcon NIM_DELETE, ni
End Sub

Public Sub TrayBalloon(ByVal MyForm As Form, ByVal sBaloonText As String, sBallonTitle As String, Optional ByVal bFlag As bFlag)
    With ni
        .cbSize = Len(ni)
        .hWnd = MDIForm1.hWnd
        .uID = vbNull
        .uFlags = NIF_INFO
        .dwInfoFlags = bFlag
        .szInfoTitle = sBallonTitle & vbNullChar
        .szInfo = sBaloonText & vbNullChar
    End With
    Shell_NotifyIcon NIM_MODIFY, ni
End Sub

Public Sub TrayTip(ByVal MyForm As Form, ByVal sTipText As String)
  With ni
        .cbSize = Len(ni)
        .hWnd = MDIForm1.hWnd
        .uID = vbNull
        .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
        .szTip = sTipText & vbNullChar
  End With
  Shell_NotifyIcon NIM_MODIFY, ni
End Sub
2015-08-19 15:30



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444406-1-1.html




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

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