RE:Ejecutable en el reloj
En un modulo copia el siguiente codigo
Public Declare Function SetWindowLongA Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProcA Lib "user32" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function Shell_NotifyIconA Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public Type NOTIFYICONDATA
cbSize As Long ' size of the structure
hWnd As Long ' the handle of the window
uID As Long ' an unique ID for the icon
uFlags As Long ' flags(see below)
uCallbackMessage As Long ' the Msg that call back when a user do something to the icon
hIcon As Long ' the memory location of the icon
szTip As String * 64 ' tooltip max 64 characters
End Type
Public Const NIM_ADD = &H0 ' add an icon to the system tray
Public Const NIM_MODIFY = &H1 ' modify an icon in the system tray
Public Const NIM_DELETE = &H2 ' delete an icon in the system tray
Public Const NIF_MESSAGE = &H1 ' whether a message is sent to the window procedure for events
Public Const NIF_ICON = &H2 ' whether an icon is displayed
Public Const NIF_TIP = &H4 ' tooltip availibility
Public formloaded As Boolean
Public oldproc As Long
Public Function proc&(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long)
' right button release on the icon
' so pop up a menu
' change 517 to:
' 516 --- right button down
' 518 --- right button double click
' 513 -- left button down
' 514 -- left button up
' 515 -- left button double click
' 519 -- middle button down ( for some mouse only )
' 520 -- middle button up
' 521 -- middle button double click
If Msg = 1400 And lParam = 517 And formloaded Then Form1.PopupMenu Form1.mnu
' let VB handle the rest
proc = CallWindowProcA(oldproc, hWnd, Msg, wParam, lParam)
End Function
'En un Form copia el siguiente codigo
Option Explicit
Private Sub clo_Click()
Unload Form1
End Sub
Private Sub Form_Load()
Dim nid As NOTIFYICONDATA
With nid
.cbSize = Len(nid) ' size of this structure
.hWnd = Form1.hWnd ' memory location(handle) for the processor of its message and icon
.uID = 0 ' the unique ID for the icon. must be different from the other sys tray icon
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP ' notify of message, display icon, display tooltip
.uCallbackMessage = 1400 ' message used to be notified when there's event. any number greater than 1300 will do
.hIcon = Form1.Icon ' assign the icon to the form's icon
.szTip = "Tooltip here" & vbNullChar ' terminate the string with vbNullChar or Chr(0)
End With
' Shell_NotifyIconA ID_OF_ICON, NOTIFYICONDATA
Shell_NotifyIconA NIM_ADD, nid
' oldproc is the address(memory location) of the original window procedure
oldproc = SetWindowLongA(Me.hWnd, -4, AddressOf proc)
End Sub
Private Sub Form_Paint()
formloaded = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
' the form unloads
' remove the icon from the sys tray
Dim nid As NOTIFYICONDATA
With nid
.hWnd = Me.hWnd
.cbSize = Len(nid) ' size of structure
.uID = 0 ' the id we set earlier
End With
' delete the icon!
Shell_NotifyIconA NIM_DELETE, nid
' set the window procedure back to the original
' otherwise if stop using the vb stop button, it will crash
' usually won't be a big problem, because mine has crash many times
SetWindowLongA Me.hWnd, -4, oldproc
End Sub
Private Sub hid_Click()
Me.Hide
End Sub
Private Sub how_Click()
MsgBox "I'm fine."
End Sub
Private Sub sho_Click()
Form1.Show
End Sub
' Tené en cuenta que debes crear un menu en el formulario llamda mnu y nada mas