I have my code as defined here.
The icon shows in the system tray ok, but when I try to doubleclick the icon, the Picture1_DblClick event doesn't fire.
Printable View
I have my code as defined here.
The icon shows in the system tray ok, but when I try to doubleclick the icon, the Picture1_DblClick event doesn't fire.
here try this:
VB Code:
'Puts app icon in the system tray Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean 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 Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2 Private Const WM_MOUSEMOVE = &H200 Private Const NIF_MESSAGE = &H1 Private Const NIF_ICON = &H2 Private Const NIF_TIP = &H4 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Private Const WM_RBUTTONDBLCLK = &H206 Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private SysTray As NOTIFYICONDATA Dim Result As Long Private Sub StartInSysTray() SysTray.cbSize = Len(SysTray) SysTray.hWnd = Picture1.hWnd SysTray.uId = 1& SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE SysTray.ucallbackMessage = WM_MOUSEMOVE 'change the below line to the desired icon SysTray.hIcon = Me.Icon SysTray.szTip = App.EXEName & ".exe" Shell_NotifyIcon NIM_ADD, SysTray Me.Hide End Sub Private Sub Form_Load() StartInSysTray End Sub Private Sub Form_Unload(Cancel As Integer) 'Remove the icon from the system tray SysTray.cbSize = Len(SysTray) SysTray.hWnd = Picture1.hWnd SysTray.uId = 1& Shell_NotifyIcon NIM_DELETE, SysTray End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) Static rec As Boolean, msg As Long Dim RetVal As String Dim returnstring Dim retvalue msg = x / Screen.TwipsPerPixelX If rec = False Then rec = True Select Case msg Case WM_LBUTTONDOWN Me.Show Me.WindowState = vbNormal Case WM_LBUTTONUP Case WM_RBUTTONblck 'Bring up the menu if the right mouse button is clicked over the icon 'what is this for? If Button = vbRightButton Then PopupMenu me.mnuFile End If ' Case WM_RBUTTONUP End Select rec = False End If End Sub
does that work?
The icon shows in the system tray ok, but when I try to doubleclick the icon, the Picture1_DblClick event doesn't fire.
Thats because your using Picture1_DblClick not Form_DblClick. The picture in the systray isn't a picture on a Form, its the Form Icon.
There are loads of examples of using systray on here, do a search for "systray"
Here is a systray I posted.
http://www.vbforums.com/showthread.php?threadid=288456&
Yes, this works. Thank you very much.Quote:
Originally posted by rotcrules
here try this:
VB Code:
'Puts app icon in the system tray Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean 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 Const NIM_ADD = &H0 Private Const NIM_MODIFY = &H1 Private Const NIM_DELETE = &H2 Private Const WM_MOUSEMOVE = &H200 Private Const NIF_MESSAGE = &H1 Private Const NIF_ICON = &H2 Private Const NIF_TIP = &H4 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Private Const WM_RBUTTONDBLCLK = &H206 Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private SysTray As NOTIFYICONDATA Dim Result As Long Private Sub StartInSysTray() SysTray.cbSize = Len(SysTray) SysTray.hWnd = Picture1.hWnd SysTray.uId = 1& SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE SysTray.ucallbackMessage = WM_MOUSEMOVE 'change the below line to the desired icon SysTray.hIcon = Me.Icon SysTray.szTip = App.EXEName & ".exe" Shell_NotifyIcon NIM_ADD, SysTray Me.Hide End Sub Private Sub Form_Load() StartInSysTray End Sub Private Sub Form_Unload(Cancel As Integer) 'Remove the icon from the system tray SysTray.cbSize = Len(SysTray) SysTray.hWnd = Picture1.hWnd SysTray.uId = 1& Shell_NotifyIcon NIM_DELETE, SysTray End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) Static rec As Boolean, msg As Long Dim RetVal As String Dim returnstring Dim retvalue msg = x / Screen.TwipsPerPixelX If rec = False Then rec = True Select Case msg Case WM_LBUTTONDOWN Me.Show Me.WindowState = vbNormal Case WM_LBUTTONUP Case WM_RBUTTONblck 'Bring up the menu if the right mouse button is clicked over the icon 'what is this for? If Button = vbRightButton Then PopupMenu me.mnuFile End If ' Case WM_RBUTTONUP End Select rec = False End If End Sub
does that work?