| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 638 人关注过本帖
标题:托盘两次点击的问题
只看楼主 加入收藏
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
结帖率:78.95%
收藏
已结贴  问题点数:20 回复次数:6 
托盘两次点击的问题
唉,旧帖无人问津,新开个帖

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
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:7 
不懂,顶一下吧

一片落叶掉进了回忆的流年。
2015-09-07 16:38
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
收藏
得分:7 
将所有窗体的mdichild属性设为true可解决问题1
将事件MDIForm_MouseMove里的show和窗口最大化对调下即可解决问题2,如下:
  Select Case lMsg
    Case LeftUp
      Me.Show
      Me.WindowState = vbMaximized

改成
  Select Case lMsg
    Case LeftUp
      Me.WindowState = vbMaximized
      Me.Show

能编个毛线衣吗?
2015-09-08 09:46
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
wmf2014
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:216
帖 子:2039
专家分:11273
注 册:2014-12-6
收藏
得分:0 
回复 4楼 linandceline
我测试正常,不知道你的子窗口做什么会导致你说的情况发生,无法模拟解决。

能编个毛线衣吗?
2015-09-08 10:42
linandceline
Rank: 2
等 级:论坛游民
威 望:2
帖 子:88
专家分:47
注 册:2014-12-19
收藏
得分:0 
回复 5楼 wmf2014
图片附件: 游客没有浏览图片的权限,请 登录注册

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

更离奇的是,新建一个空子窗体来替换它或者把原窗体的控件删掉又可以了
2015-09-08 13:47
renxiaoyao36
Rank: 9Rank: 9Rank: 9
来 自:七宝中学
等 级:贵宾
威 望:31
帖 子:347
专家分:1077
注 册:2014-9-18
收藏
得分:7 
托盘中若有Tab选项卡类型的外部部件会导致托盘无法收到点击讯息。这是我遇到的,比你的严重多了,你的好歹双击可以,我的不管如何只要有Tab之类的全部挂。哎。

编程蛋疼的不是枯燥,而是辛辛苦苦编完几百行的代码,运行,“Runtime Error “xxx””。
2015-09-13 21:13
快速回复:托盘两次点击的问题
数据加载中...
 
   



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

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