Entra

View Full Version : Realizzare un servizio e icona tray bar


gohan
04-09-2002, 15:54
è possibile realizzare un servizio per windows 2000 o XP che quando è attivo mostri un'icona nella tray bar? (insomma come fa solitamente un antivirus)
E che facendo click col mouse mi apra un menu contestuale e col doppio click una finestra?
Sto usando VB.NET, ma riesco solo a far comparire l'icona nella tray ma cliccando non succede nulla.
Che posso fare? sapete dove posso trovare degli esempi?
Grazie a tutti

cionci
04-09-2002, 18:19
Realizzare il servizio è una cosa diversa...
Solitamente lavorano in questo modo :

- il servizio si mette a girare per conto suo (è un programma senza interfaccia) e parte automaticamente all'avvio della macchina (non dopo il login)...gli antivirus sono solitamente dei servizi...
- il programma per la system tray viene lanciato all'avvio tramite esecuzione automatica o qualche altro sistema...e questo gestisce il registro di configurazione del servizio...

Peccato che tu stia usando VB.Net...avevo già n programma pronto in VB :

'Download the full source+pictures+... at [url]http://www.allapi.net/php/redirect/redirect.php?action=download&id=38[/url]
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 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_RBUTTONUP = &H205

Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayI As NOTIFYICONDATA
Private Sub Form_Load()
TrayI.cbSize = Len(TrayI)
'Set the window's handle (this will be used to hook the specified window)
TrayI.hWnd = pichook.hWnd
'Application-defined identifier of the taskbar icon
TrayI.uId = 1&
'Set the flags
TrayI.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
'Set the callback message
TrayI.ucallbackMessage = WM_LBUTTONDOWN
'Set the picture (must be an icon!)
TrayI.hIcon = imgIcon(2).Picture
'Set the tooltiptext
TrayI.szTip = "Recent" & Chr$(0)
'Create the icon
Shell_NotifyIcon NIM_ADD, TrayI

Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the icon
TrayI.cbSize = Len(TrayI)
TrayI.hWnd = pichook.hWnd
TrayI.uId = 1&
Shell_NotifyIcon NIM_DELETE, TrayI
End
End Sub
Private Sub mnuPop_Click(Index As Integer)
Select Case Index
Case 0
MsgBox "KPD-Team 1998" + Chr$(13) + "URL: [url]http://www.allapi.net/[/url]" + Chr$(13) + "E-Mail: [email]KPDTeam@Allapi.net[/email]", vbInformation + vbOKOnly
Case 2
Unload Me
End Select
End Sub
Private Sub pichook_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Msg = X / Screen.TwipsPerPixelX
If Msg = WM_LBUTTONDBLCLK Then
'Left button double click
mnuPop_Click 0
ElseIf Msg = WM_RBUTTONUP Then
'Right button click
Me.PopupMenu mnuPopUp
End If
End Sub
Private Sub Timer1_Timer()
Static Tek As Integer
'Animate the icon
Me.Icon = imgIcon(Tek).Picture
TrayI.hIcon = imgIcon(Tek).Picture
Tek = Tek + 1
If Tek = 3 Then Tek = 0
Shell_NotifyIcon NIM_MODIFY, TrayI
End Sub

gohan
04-09-2002, 19:05
Lo so he un servizio gira per conto suo! ma se abilitavo il servizio ad interagire col desktop, mi faceva comparire l'icona nella tray ma senza poter fare nulla.
Per poter aprire qualcosa dall'iconcina, l'unico modo che abbiamo trovato è quello di creare un'applicazione con form trasparente.
Solo che un'altra applicazione scritta in VB.NET, oltre a quelle che ci sono già, occuperebbe troppa memoria (considera che minimo ogni processo tiene 10-12 MB di ram!:eek: ).
Quindi abbiamo deciso d'integrare la gestione del servizio in un altro programma.
Grazie per l'aiuto, e vedrò se qualche parte di codice mi possa essere utile.;)