Results 1 to 2 of 2

Thread: problem w/ systray

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 1999
    Posts
    52

    Post

    I have a form that contains a PicutreBox called picTray. I then have this code:
    Code:
    Private 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
    
    Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    Private Const NIF_ICON = &H2
    Private Const NIF_MESSAGE = &H1
    Private Const NIF_TIP = &H4
    Private Const NIM_ADD = &H0
    Private Const NIM_DELETE = &H2
    Private Const NIM_MODIFY = &H1
    Private Const WM_MOUSEMOVE = &H200
    Private Const WM_LBUTTONDBLCLK = &H203
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_RBUTTONDOWN = &H204
    Private tTrayIcon As NOTIFYICONDATA
    
    Private Sub Form_Load()    
    'Create a Tray Icon
    picTray.Visible = False
    With tTrayIcon
        .hIcon = Icon
        .hwnd = picTray.hwnd
        .szTip = "Test" & Chr(0)
        .uCallbackMessage = WM_MOUSEMOVE
        .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
        .uID = 1
        .cbSize = Len(tTrayIcon)
    End With
    End Sub
    
    Private Sub Form_Resize()
    If WindowState = vbMinimized Then
        Hide
        'Send it to the tray
        Shell_NotifyIcon NIM_ADD, tTrayIcon
    End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Remove the Tray Icon
        Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub
    
    Private Sub picTray_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Select Case ScaleX(X, vbTwips, vbPixels)
        Case WM_RBUTTONDOWN
        Case WM_LBUTTONDBLCLK
            Me.Show
            Me.WindowState = vbNormal
    End Select
    End Sub
    It works yet it doesn't...Everything works fine except when I double click which would call this code:
    Code:
    Private Sub picTray_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Select Case ScaleX(X, vbTwips, vbPixels)
        Case WM_RBUTTONDOWN
        Case WM_LBUTTONDBLCLK
            Me.Show
            Me.WindowState = vbNormal
    
    End Select
    End Sub
    I have to double click and then double click again to make the form show itself. Anyone know what's up?? Thanks in advance.


    Edited by _eclipsed_ on 03-10-2000 at 12:19 AM
    -Adam
    Yahoo!: _eclipsed_
    ICQ:18534929

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Posts
    82

    Post

    If I could give you a reason why it behaves this way I would but I really have no idea. My best guess is that it seems to show the form temporarily and the re-send it to the tray. Re entering the resize event pehaps. Anyway.... this seems to correct it

    'define mod level var
    private trayed as boolean

    Private Sub Form_Resize()
    If trayed Then: Exit Sub
    If WindowState = vbMinimized Then
    Hide
    'Send it to the tray
    Shell_NotifyIcon NIM_ADD, tTrayIcon
    trayed = True
    End If
    End Sub

    Private Sub picTray_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Select Case ScaleX(X, vbTwips, vbPixels)
    Case WM_RBUTTONDOWN
    Case WM_LBUTTONDBLCLK
    Me.Show
    Me.WindowState = vbNormal
    trayed = False
    Case Else
    End Select
    End Sub

    hope this helps...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width