Results 1 to 4 of 4

Thread: SysTray Help Please!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    Unhappy

    I've created a program that shrinks into the systray the only problem is that I can't seem to be able to show a menu of some sort on the right mouse click?

    Help!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    What code/control are you using?
    the picturebox you refer to when you initiated the tray icon will fire a event, not sure if it was the mousedown or what but the first parameter will tell you which mouse button was pressed and if you doubleclicked or whatever.
    Maybe it's easier with controls, i have one on my homepage with all the events you need
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Addicted Member
    Join Date
    Jan 2000
    Location
    Fresno, California, USA
    Posts
    195
    Go here to get Microsoft's control with examples on how to use.

    http://msdn.microsoft.com/vbasic/downloads/controls.asp

  4. #4
    Guest
    Use this easier code which will pop up a menu when the right mouse button is clicked on the icon in the systray:

    Code:
    'Module code:
    
    Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    Public Const WM_LBUTTONUP = &H202
    Public Const WM_RBUTTONUP = &H205
    Public Const WM_MOUSEMOVE = &H200
    
    
    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 VBGTray As NOTIFYICONDATA
    
    
    'Form Declarations:
    Private Sub GoSystemTray()
      VBGTray.cbSize = Len(VBGTray)
      VBGTray.hwnd = Me.hwnd
      VBGTray.uId = vbNull
      VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
      VBGTray.ucallbackMessage = WM_MOUSEMOVE
      VBGTray.hIcon = Me.Icon
      'tool tip text
      VBGTray.szTip = Me.Caption & vbNullChar
      Call Shell_NotifyIcon(NIM_ADD, VBGTray)
      App.TaskVisible = False   'remove application from taskbar
      Me.Hide
    End Sub
    
    'Form Code:
    
    Private Sub Form_MouseMove(button As Integer, Shift As Integer, X As Single, Y As Single)
      Static lngMsg As Long
      Static blnFlag As Boolean
      Dim result As Long
    lngMsg = X / Screen.TwipsPerPixelX
      If blnFlag = False Then
            blnFlag = True
            Select Case lngMsg
            'right-click
            Case WM_RBUTTONUP
              result = SetForegroundWindow(Me.hwnd)
              PopupMenu MyPopUpMenu
             Case WM_LBUTTONUP
              result = SetForegroundWindow(Me.hwnd)
              PopupMenu MyPopUpMenu
            End Select
            blnFlag = False
     End If
    End Sub
    
    Private Sub Form_Resize()
    If Me.WindowState = 1 Then
    Call GoSystemTray
    End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
      VBGTray.cbSize = Len(VBGTray)
      VBGTray.hwnd = Me.hwnd
      VBGTray.uId = vbNull
      Call Shell_NotifyIcon(NIM_DELETE, VBGTray)
      Unload Me
      Set Form1 = Nothing
      End
    End Sub

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