Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to: System Tray Icon? 1

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
How can I have a program show itself in the system tray? -Ovatvvon :-Q
 
'Put this code in form load event
Set SysTray1.Picture = LoadPicture(app.path "&" "\View.ico")
SysTray1.Add
Me.hide

'then continue with your later part of the code here.

Cheers!!!
 
When running the program within VB, it comes up with an error saying "SysTray1" is undefined in line 1 of the code you showed.

Do I need to Dim SysTray1 to a control type or somthing else? -Ovatvvon :-Q
 
Systray is not a standard VB control. There are several commercial systray controls (search on Google for systray) and a Microsoft VB4 sample code, written in VB.

Have a look at:

There's another version at
Techaspirer,
If you post code using non-standard controls, it's usuall worth noting which controls you're talking about, and where they come from. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Hey
sorry ya. actually i have a separate OCX file for systray. how do i upload that in this forum. if therez any way juz tell me. or i can also email u this file. its kust 36.2 KB.

Extremely sorry....
Cheers!!!
 
I would appreciate a copy of that ocx. My email address is greg.palmer@totalise.co.uk

Many Thanks Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
Hey actually i used this for my project Folder security. this worked for me well. juz make a try. i hope this works out well. then... in ur project you'll find icon property. juz give the path of the icon which needs to be placed for your priject.
Hope I'm clear...if u have some prob..tell me..i'll try it once again.
The code goes here!!!
*******

'To Display Icon on the task bar while runtime

'An API call to inform the Shell for displaying the icon at taskbar
Private Declare Function Shell_NotifyIcon Lib "SHELL32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private abd As NOTIFYICONDATA

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 Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const Mouse_Move = 512
Private Const Mouse_Left_Down = 513
Private Const Mouse_Left_Click = 514
Private Const Mouse_Left_DbClick = 515
Private Const Mouse_Right_Down = 516
Private Const Mouse_Right_Click = 517
Private Const Mouse_Right_DbClick = 518
Private Const Mouse_Button_Down = 519
Private Const Mouse_Button_Click = 520
Private Const Mouse_Button_DbClick = 521

Private Sub Form_Load()
On Error Resume Next
Dir1.Path = "c:\"
With abd
.cbSize = Len(abd)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = Mouse_Move
.hIcon = Me.Icon
.szTip = "Your project name u r runnning" & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, abd
Me.Hide
End Sub
 
I don't know about anyone else, but I can an error saying "Dir1 is undefined". Looking at the code, it's not declared. Is it not supposed to be? What could be causeing this error? -Ovatvvon :-Q
 
This code has to be in a seperate ocx file? Honestly, as I'm sure it's apparent, I'm still learning. Could you give me a quick overview of what ocs files are and how to create them or how to attach them to the regular vb application? I don't need an in-depth explaination. Just enough to get me started and I'll explore from there. -Ovatvvon :-Q
 
Try this for OCX and ActiveX control creation:
Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
ya...
i can send u the file. but how do i attach it. can u give ur mail id or some other means to upload the file.
 
well, we're not supposed to post our email addresses in the forums. However the code for the ocx file is above, right?

How would I make the ocx file with that code. Just put it in a form of it's own? And then, once I create the ocx form, how would I call it from the main program so it will place the icon in the system tray?

(Going to check out that link now) -Ovatvvon :-Q
 
Hey..
u can't paste the OCX code juz like that. Anyway I have attached the file in the foll link. u can download frm that.
goto this link
after u sign in there u'll find "files" link on the left side. there u'll find a file systray.ocx. downlaod that.all i can do is this.if u have doubts stilll feel free to ask me.

1. open ur project
2. goto Project- components
3. click browse and locate ur ocx file
4. then its get added up in your proj tooolbar.
5. click that icon and drag it to ur project form.
6. change its name to systray1 in properties box
7. u r now done and add the following code.

'Put this code in form load event
Set SysTray1.Picture = LoadPicture(app.path "&" "\View.ico")
SysTray1.Add
Me.hide

'then continue with your later part of the code here.

Hope this is perfect and helps u!!!
 
It works now! :)

But now there's a different problem. When the program is hidden, I wanted the tray icon to appear so the user could double click on that and have the program re-appear. That way the administrator could shut down the program if need be.

Is there a way to make it so the user can click on the icon and have it show the program again? Does that have to be done in the ocx file? -Ovatvvon :-Q
 
Nevermind, I see now it can be like other procedures. So it works!

Thanks for your help!!

Is there a way I can see the ocx file's code...the one that I downloaded? How can I see that and/or interact with it? -Ovatvvon :-Q
 
fine...nice to hear. Create a menu using menu editor which contain "hide" and "show" menu. Then during form load make that menu editor invisible.

then write an event like this:

Private Sub SysTray1_LeftDblClick()
PopupMenu test1
' here popmenu is the key word and 'test1' is the menu editor name
End Sub

'then write a code for show and hide.

show_click()
me.show

hide_click()
me.hide

Here show and hide are the event name in menu editor.
Hope i'm clear....
if u want i can send u the file wht i have. i'll post in the same yahoo gp written above if u need that.

Cheers!!!
 
oh, I didn't need to know about menu creation or anything. I just wanted to know how to create an ocx file in vb. -Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top