Visual Basic - Uso del Systray

Life is soft - evento anual de software empresarial
 
Vista:

Uso del Systray

Publicado por Besstiia (1 intervención) el 14/10/2005 18:36:44
Hola a Todos,

Yo necesitaba saber como cambiar y añadir nuevos textos, con este control. Los textos a los que me refiero son al darle con el botón derecho encima del icono.

-Restore
-Exit

Son los actuales que aparecen, pero no sé como cambiarlos.

Muchas gracias de antemano a todos.

Copio el código de ejemplo que necesito modificar:

Option Explicit

'declare external procedures
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, _
lpData As NOTIFYICONDATA) As Long

Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long

'...constants
Const WM_MOUSEMOVE = &H200

Const WM_LBUTTONDBLCLK = &H203
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202

Const WM_MBUTTONDBLCLK = &H209
Const WM_MBUTTONDOWN = &H207
Const WM_MBUTTONUP = &H208

Const WM_RBUTTONDBLCLK = &H206
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205

Const NIM_ADD = &H0
Const NIM_DELETE = &H2
Const NIM_MODIFY = &H1

Const NIF_ICON = &H2
Const NIF_MESSAGE = &H1
Const NIF_TIP = &H4

'declare enums
Public Enum enumSystrayIconModifier
modifyIcon = &H2
modifyTip = &H4
End Enum

'declare types
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

'declare variables
Private vSystrayIcon As NOTIFYICONDATA
Private vLastWindowState As FormWindowStateConstants

Private Sub Form_Load()
vLastWindowState = Me.WindowState
AddSystrayIcon Me.Caption
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'init
Dim msg As Long

'get message
msg = ScaleX(X, ScaleMode, vbPixels)

'handle message
Select Case msg
Case WM_LBUTTONDOWN
If Not Me.WindowState = vbMinimized Then Me.SetFocus

Case WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK
If Me.WindowState = vbMinimized Then
Me.WindowState = vLastWindowState
If Not Me.Visible Then Me.Visible = True
Else
Me.WindowState = vbMinimized
End If

If Me.Visible Then Me.SetFocus

Case WM_RBUTTONUP
Call SetForegroundWindow(Me.hwnd)
ShowSystrayMenu
End Select
End Sub

Private Sub Form_Resize()
Select Case Me.WindowState
Case vbMinimized
If MinimizeToSystray Then Me.Hide
Case vbMaximized
vLastWindowState = vbMaximized
Case Else
vLastWindowState = vbNormal
End Select
End Sub

Private Sub Form_Unload(Cancel As Integer)
RemoveSystrayIcon
End Sub

Private Sub AddSystrayIcon(TrayTipText As String)
'init
With vSystrayIcon
.cbSize = Len(vSystrayIcon)
.hIcon = Me.Icon
.hwnd = Me.hwnd
.szTip = TrayTipText & Chr$(0)
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON + NIF_MESSAGE + NIF_TIP
.uID = vbNull
End With

'add icon to systray
Call Shell_NotifyIcon(NIM_ADD, vSystrayIcon)
End Sub

Private Sub ModifySystrayIcon(ModifyType As enumSystrayIconModifier, _
ByVal NewValue As Variant)

'set elements / values to modify
Select Case ModifyType
Case modifyIcon
vSystrayIcon.hIcon = CLng(NewValue)
Case modifyTip
vSystrayIcon.szTip = CStr(NewValue) & Chr$(0)
End Select

'send modify message to systray
Call Shell_NotifyIcon(NIM_MODIFY, vSystrayIcon)
End Sub

Private Sub RemoveSystrayIcon()
Call Shell_NotifyIcon(NIM_DELETE, vSystrayIcon)
End Sub

Private Sub ShowSystrayMenu()
'configure menu
mnuPopUpRestore.Visible = (Me.WindowState = vbMinimized)

'show menu
PopupMenu mnuPopUp
End Sub

Private Function MinimizeToSystray() As Boolean
MinimizeToSystray = True
End Function

Private Sub mnuPopUpExit_Click()
Unload Me
End Sub

Private Sub mnuPopUpRestore_Click()
Me.WindowState = vLastWindowState
If Not Me.Visible Then Me.Visible = True
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:Uso del Systray

Publicado por Raúl Santiago (178 intervenciones) el 17/10/2005 09:22:22
Bueno, asi como lo haces ni idea, yo normalmente lo hago con el systray.ocx y este ya me hace todo, es bastante simple de manejar, unos ejemplos de como usarlo estan publicados aqui:

http://www.lawebdelprogramador.com/temas/iconoreloj.php

http://www.lawebdelprogramador.com/temas/iconomovimientoreloj.php

Espero te sirva
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar