Discussion Locked

Program running always on Windows

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello, friends...

I'd like to write a program running always on windows with an ICON appear to the right of the taskbar (near by CLOCK).

Please help me how to make my program have an ICON like this?

Thanks,

PNAKiet

8 replies

by thechas

This is not an answer, but a comment.

You are looking to have your program run from the "System Tray".
Programs that run in the system tray, are similar to TSR (terminate and stay resident) programs from the DOS days.

Please include an option to disable the service in the program user preferences.
I personally disable 90 percent of the programs that attempt to keep an icon in the system tray.

Off the soapbox.
There are not a lot of programmers spending time at this site.
I recommend that you take a look at Tech Republic's sister site www.builder.com.com
There is a discussion center there:
http://builder.com.com/5221-6230-0.html

There are also a number of articles on programming, and I would expect they even have sample Visual Basic code for using the System Tray.

Chas

by mobiletech

pnakiet, here is a code snippet

declarations

Option Explicit

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
'Tray Icon variables
'Tray Constants
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
'Tray Button Constants
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const sckConnected = 7
Public Const sckConnecting = 6
Public g_oTrayIcon As NOTIFYICONDATA
Public Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, _
pnid As NOTIFYICONDATA) As Boolean

your code

Public Sub loadIcon()
'Setup initial Tray Icon
Dim ret As Boolean
Dim frmCheck As Boolean
On Error GoTo errHandler
With g_oTrayIcon
.cbSize = Len(g_oTrayIcon)
.hWnd = frm1.hWnd
.uId = 1&
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.ucallbackMessage = WM_MOUSEMOVE
.hIcon = frm1.Icon
.szTip = "Your app name" & Chr$(0)
End With
ret = Shell_NotifyIcon(NIM_ADD, g_oTrayIcon)

Exit Sub

errHandler:
End Sub

Public Sub unloadIcon()
'Remove The Tray Icon
With g_oTrayIcon
.cbSize = Len(g_oTrayIcon)
.hWnd = frmServiceMgr.hWnd
.uId = 1&
End With

Shell_NotifyIcon NIM_DELETE, g_oTrayIcon
LogNTEvent "Unloading Icon", EVENTLOG_INFORMATION_TYPE, _
generateRandomEventId

End Sub

you will also need to use the mouse o=move of the form to handle the click events on the icon

by rrv

Only way is to use Shell_NotifyIcon API. You can also have a user defined menu for this icon click events. This Icon can be a dynamic icon like the changing bar icon of Task Manager when minimised. Check MSDN.Microsoft.com for sample code in VB.

RV

This discussion is closed to new replies.