标题:托盘两次点击的问题
取消只看楼主
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
结帖率:78.95%
已结贴  问题点数:20 回复次数:2 
托盘两次点击的问题
唉,旧帖无人问津,新开个帖

MDI窗口的托盘,同时加入了闪烁图标,代码在下面列出来
问题有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-09-07 15:20
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
回复 3楼 wmf2014
看到你在这个帖子里,我死活不愿意走啊,就等你指点

1、MDICHILD都是设置好的,这点不会错,所以,问题1仍然是存在的

2、问题2,我是调整判定位置来处理的,目前调试没有发现问题
不知是否正确
Private Sub MDIForm_Load()
Formministatus = False
......
end sub

Private Sub MDIForm_Resize()
If Me.WindowState = vbMinimized and Formministatus = False Then
  Formministatus = True
  me.hide
  ......
else
  Formministatus = False
  ......
end if
end sub
2015-09-08 09:59
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
得分:0 
回复 5楼 wmf2014

什么都没设置呀。
里面有两个listview和一个timer

更离奇的是,新建一个空子窗体来替换它或者把原窗体的控件删掉又可以了
2015-09-08 13:47



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




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

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