|
-
Jun 26th, 2000, 03:38 AM
#1
Thread Starter
Member
is there any way to get my program's icon into the system tray without having to distribute an ocx file with it? I know the ocx is the easy way, but there ususally is a harder, but better way with API i jsut dont know it this time. So if anyone does please help me out here.
-
Jun 26th, 2000, 05:43 PM
#2
Do a search for system tray on this webpage
http://www.vb-world.net/cgi-bin/sear...hereto=VBWORLD
And you will get results like:
http://www.vbsquare.com/tips/tip178.html
Wich explain it all
-
Jun 28th, 2000, 12:17 AM
#3
Monday Morning Lunatic
if you subclass your own window, then you don't need the PictureBox, and get the messages sent directly to your program.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 28th, 2000, 01:08 AM
#4
Try this. First you new to make a 2 Forms and a Module. The first Form is called frmTray. The 2nd Form is called Form1.
On frmTray, make a PictureBox or an ImageBox with an Icon in it and set the Index property to 0. Set the ShowInTaskBar property for Form1 to False.
Add thid code to the Module. Make sure the Startup Form is Sub Main.
Code:
Option Explicit
Sub Main()
Load frmTray
Form1.Show
End Sub
Now add this code to frmTray.
Code:
Option Explicit
'Messages
Private Const NIM_ADD = &H0 'Adds an icon to the taskbar notification area
Private Const NIM_MODIFY = &H1 'Changes the icon, tooltip text or notification message for an icon in the notification area
Private Const NIM_DELETE = &H2 'Deletes an icon from the taskbar notification area
'Flags
Private Const NIF_MESSAGE = &H1 'hIcon is valid
Private Const NIF_ICON = &H2 'uCallbackMessage is valid
Private Const NIF_TIP = &H4 'szTip is valid
Private Const WM_MOUSEMOVE = &H200 'MouseMove message identifier
'Messages sent to the form's MouseMove event
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 Type NOTIFYICONDATA
cbSize As Long
hWnd As Long 'Handle of window that receives notification messages
uID As Long 'Application-defined identifier of the taskbar icon
uFlags As Long 'Flags indicating which structure members contain valid data
uCallbackMessage As Long 'Application defined callback message
hIcon As Long 'Handle of taskbar icon
szTip As String * 64 'Tooltip text to display for icon
End Type
Dim mtIconData As NOTIFYICONDATA
Dim mnLight As Integer
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long
Private Sub Form_Load()
AddIconToTray
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteIconFromTray 'Put cleanup code here so that it always gets executed
Set frmTray = Nothing
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static bBusy As Boolean
If bBusy = False Then
bBusy = True
Select Case CLng(X)
Case WM_LBUTTONDBLCLK ' Left button Double Clicked
Form1.Show ' Show our Form
Case WM_LBUTTONDOWN ' Left button Down
If Shell_NotifyIcon(NIM_MODIFY, mtIconData) = 0 Then
MsgBox "Unable to change icon in system tray!"
End If
Case WM_LBUTTONUP 'Left mouse button released
Case WM_RBUTTONDBLCLK 'Double-click right mouse button
Case WM_RBUTTONDOWN 'Right mouse button pressed
End Select
bBusy = False
End If
End Sub
Private Sub AddIconToTray() 'Adds an icon to the taskbar notification area
With mtIconData
.cbSize = Len(mtIconData)
.hWnd = Me.hWnd 'Use the form to receive callback messages.
.uCallbackMessage = WM_MOUSEMOVE 'Tell icon to send MouseMove messages.
.uID = 1& 'Application defined identifier
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.hIcon = imgTrayIcon(0).Picture 'Initial icon
.szTip = "ToolTipText" & Chr$(0) 'Initial tooltip for icon
If Shell_NotifyIcon(NIM_ADD, mtIconData) = 0 Then 'Create icon in tray
MsgBox "Unable to add icon to system tray!"
End If
End With
End Sub
Private Sub DeleteIconFromTray()
If Shell_NotifyIcon(NIM_DELETE, mtIconData) = 0 Then
MsgBox "Unable to delete icon from system tray!"
End If
End Sub
-
Jun 28th, 2000, 01:14 AM
#5
Monday Morning Lunatic
cunning, meg. neat idea to get round using your own message by hijacking another message and waiting for VB to catch it. Though I suppose that if you used MouseMove a lot, you'd need a separate message.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|