|
-
Nov 20th, 1999, 10:54 AM
#1
Add an Invisible Picturebox to your Form, then Paste this Code:
Code:
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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIM_MODIFY = &H1
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONDOWN = &H204
Private tTrayIcon As NOTIFYICONDATA
Private Sub Form_Load()
'Create a Tray Icon
Picture1.Visible = False
With tTrayIcon
.hIcon = Icon
.hwnd = Picture1.hwnd
.szTip = "My Tray Icon" & Chr(0)
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
.cbSize = Len(tTrayIcon)
End With
Shell_NotifyIcon NIM_ADD, tTrayIcon
End Sub
Private Sub Form_Resize()
DoEvents
If WindowState = vbMinimized Then
Hide
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Remove the Tray Icon
Shell_NotifyIcon NIM_DELETE, tTrayIcon
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_RBUTTONDOWN
'Show Popup Menu
Case WM_LBUTTONDBLCLK
'Show the Form
WindowState = vbNormal
Show
End Select
End Sub
If you want it even simpler I believe there's an OCX available on this site somewhere, which bascially does all this in the background.
Only downside is you have to ship the OCX with your Project.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 20th, 1999, 12:56 PM
#2
Frenzied Member
Does anyone know how i can
put my program in the
System Tray in an EASY way????
/ CyberCarsten
-
Nov 20th, 1999, 04:26 PM
#3
Frenzied Member
Thank you Aaron!
I'll try it!
-
Nov 20th, 1999, 04:37 PM
#4
Frenzied Member
When i place the following code
in my Private Sub Form_Load()
'Create a Tray Icon
Picture1.Visible = False
With tTrayIcon
.hIcon = Icon
.hwnd = Picture1.hwnd
.szTip = "My Tray Icon" & Chr(0)
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
.cbSize = Len(tTrayIcon)
End With
Shell_NotifyIcon NIM_ADD, tTrayIcon
VB marks : Shell_NotifyIcon NIM_ADD, tTrayIcon
and the following error occuors:
Compile Error
Sub or Function not defined
What is wrong??
/ CyberCarsten
-
Nov 21st, 1999, 01:00 AM
#5
Junior Member
I'd like to add a question here.
I'd like to use a systray icon for my program, but I'd like the program to load as a tray icon and then allow the form1 to be shown once the user click the icon in the tray and select for the program to be seen from a drop down menu.
Anyone know how to do this?
Thanks,
MiDaWe
-
Nov 21st, 1999, 06:52 AM
#6
Just Set the Forms Visible Property to False, the Load Event will still trigger creating the Tray Icon, then in the Right Click Section of the Select Case Statement, Display the PopupMenu from which you can set the Forms Visible Property to True.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 21st, 1999, 12:44 PM
#7
Guru
Try copying all of Aaron's code and not just a part. The code works on an empty form with only an invisible PictureBox in it.
------------------
Yonatan
Teenage Programmer
E-Mail: [email protected]
ICQ: 19552879
AIM: RYoni69
-
Nov 22nd, 1999, 01:41 AM
#8
Frenzied Member
It still doesn't work!
Could someone please send me the project???
[email protected]
/ CyberCarsten
-
Nov 22nd, 1999, 02:46 AM
#9
Set the Forms Visible Property to False, Add an Invisible Picturebox.
Create a Menu Call mnuPopup and add the Sub Items; mnuShowForm1 and mnuExit, make sure the Visible Property of mnuPopup is False (Unchecked).
Then paste All this code into the Forms General Section..
Code:
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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const WM_RBUTTONUP = &H205
Private tTrayIcon As NOTIFYICONDATA
Private Sub Form_Load()
With tTrayIcon
.hIcon = Icon
.hwnd = Picture1.hwnd
.szTip = Caption & Chr(0)
.uCallbackMessage = WM_MOUSEMOVE
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uID = 1
.cbSize = Len(tTrayIcon)
End With
Shell_NotifyIcon NIM_ADD, tTrayIcon
End Sub
Private Sub Form_Resize()
If WindowState = vbMinimized Then
Hide
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, tTrayIcon
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
Private Sub mnuShowForm1_Click()
Show
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_RBUTTONUP
Me.PopupMenu mnuPopup
End Select
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 22nd, 1999, 03:01 AM
#10
Frenzied Member
Hi Aaron!
Thank you for all your help!!
It finally worked!!!
And just one last Question:
Can i call the same procedure with a button??
Yours Sincierly
/ CyberCarsten
-
Nov 22nd, 1999, 04:07 AM
#11
The Form is Shown from the mnuShowForm1 Click Event, so you can either call that Event from the Command Button or Simple Show the Form, eg.
Code:
Private Sub Command1_Click()
mnuShowForm1_Click
End Sub
or..
Code:
Private Sub Command1_Click()
Show
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
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
|