Systray
How to make an application go to the systray when it's minimized? I mean only to the systray so it's not shown in the taskbar. thx
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Systray Menu Appears At Random When Program Is Not In Systray
I have a menu that is only supposed to appear when the icon in the system tray is clicked. It works fine from the system tray. But when I have the program opened the menu will appear at random times and locations. Why?
I put the debug commands in to notifiy me when the event(s) fire. This problem also occurs in all of my other programs that have this code BUT ONLY if there is a right click menu associated with that icon. I have already run Windows Update and installed VB6 SP6.
The code I am using I got from msdn.microsoft.com.
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'intDebugCnt is located in the General Declarations section of the form
intDebugCnt = intDebugCnt + 1
Debug.Print MODULE_NAME & "Form_MouseMove" & intDebugCnt
Dim Result As Long
Dim msg As Long
If Me.ScaleMode = vbPixels Then
msg = X
Else
msg = X / Screen.TwipsPerPixelX
End If
Debug.Print "X = " & X
Select Case msg
Case WM_RBUTTONUP
Debug.Print "WM_RBUTTONUP"
'517 - Display popup menu
Result = SetForegroundWindow(Me.hwnd)
Me.PopupMenu Me.mnuSysTray
Case WM_LBUTTONDBLCLK
Debug.Print "WM_LBUTTONDBLCLK"
'515 - Restore frmMain
Me.WindowState = vbNormal
cmdReturnToTray.visible = True
Result = SetForegroundWindow(Me.hwnd)
Me.Show
End Select
End Sub
How Can I Add A Systray Icon And A Systray Menu.
SupZ.... I got as pic that i want to be the systray icon. I dono how to addit. I also need to add clicking options to the icon. ex: If I right click it , a menu pups up and sais about , exit and so on. when left clicked, It restores the program.
Help?
Th,x L8ter
Systray?
how to send program to systray, and, then when i click on his icon, it restores?
Systray
I need a really good systray source code if you know which one is good please tell me. I dont want one that minimize into tray i want one that closes into tray. When click minimize it still minimizes into the taskbar.
-Hao Li-
Systray
How do make my software appear in the system tray with an icon when minimized and how do i make a menu when right-clicked on the icon in system tray.
Please help thanx
-Hao Li-
Systray
I am trying to make my program only show up in the systray. I know this is a common thing, however I did a search and did not find too much.
http://www.google.com/search?hs=tDe&...um&btnG=Search
One thing I found was fairly complicated. Anyways, I was wondering what you would recommend to do the job? Thanks.
http://www.xtremevbtalk.com/showthread.php?t=19087
Systray
What is the simplest code to make a program that run in systray ??
PLZ help me
Systray
how to make a vb application to be included inside the systray such as MSN or ICQ?
Systray Help
Hi, I got the following code example from here. How can I change it so that when a user clicks on the "X" button the program goes to the system tray instead of when the user clicks on the "-"minibuton.
Thanks
Code Code:
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
'declaration for putting the application to system tray
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
'declare constants
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
'The following constants are used to determine the mouse input on the
'Left-click
Private Const WM_LBUTTONDBLCLK = &H203 'Double click
Private Const WM_LBUTTONDOWN = &H201 'down
Private Const WM_LBUTTONUP = &H202 'up
'Right-click
Private Const WM_RBUTTONDBLCLK = &H206 'Double click
Private Const WM_RBUTTONDOWN = &H204 'down
Private Const WM_RBUTTONUP = &H205 'up
'Dimension a variable as the user-defined data type.
Dim nid As NOTIFYICONDATA
Private Sub Ex_Click()
Unload Me
Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
End Sub
' one main menu by Caption"Menu" name "TrayMenu"
' one sub menu by name caption "Exit" name "Ex"
' one sub menu by name caption "Show" name "Show"
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
MsgBox "you clicked me!"
' Me.PopupMenu TrayMenu 'if u want u can call the popup menu
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
Case WM_RBUTTONDOWN
Case WM_RBUTTONUP
Me.PopupMenu TrayMenu 'call the popup menu
Case WM_RBUTTONDBLCLK
End Select
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
Me.Hide
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon
'u can give a tool tip text here
nid.szTip = "My System Tray Message" & vbNullChar
'Call the Shell_NotifyIcon function to add the icon to the System Tray, defulte form's icon
Shell_NotifyIcon NIM_ADD, nid
Else
End If
End Sub
Private Sub Show_Click()
Me.WindowState = 0
Me.Show
Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
End Sub
Systray
i cant seem to find this code on the internet, so there might not be one.
I am trying to hide the system tray so just the clock and the taskbar is showing.
Please let me know if it is possible, and if you know the code please post it.
Systray
Hi
I have a VB6 program that alert the user about his schedule,I want to include a shortcut of this program into the systray toolbar.
Also,upon starting up the PC,i want to load this program
How can I do it?
thanks
Systray Help
Hey, I cant seem to get ANY of the examples of minimizing to the System tray and then restoring the form when clicking the icon to work. With every example it minimizes fine, but then the Icon just sits in the systray.
Please help me out with this. Sorry for the inconvience..
- BorT
Need Help With Systray App
I've tried to get my systray app to work, but i haven't managed in 4 hours, so i'm kinda tired at it. If anyone could take a look at it, I would be grateful.
if you want any more info, just tell me
Systray IP
*first post first thread*
Alright im making a very very simple program that hides in the notification area by the clock down at the task bar, that when you hover over the icon it shows your IP address.
I already made the code for getting the local IP, i know its one line of code its easy, and right now all my program does is change the form caption to the IP address. I was guessing that you needed to do this in order for the tooltip to display the IP.
My Own Systray????
Hi again.
I would like to make my own systray, but I don't know how to handle programs, which want to show an icon in it. Know this somebody?
------------------
Thanks,
John, 14 years old
App In Systray
Is there a way to determine if my current app is also running in the systray?
Systray
How can I add my program link in systray.
Who Try This ? (VB6 From Systray)
Hello,
I don't know if somebody have experience this !
If you call a VB program from the systray (SE: Windows ME and Office 2000), it launch systematically the Microsoft Office 2000 SETUP !...
I have try to put only the call of VB6.EXE in the systray and I get the same problem (see bitmap)
Please HELP !.....
Thanks,
Thierry Demoy
Systray
Can somebody plese tell me how i can put the program sortoff into the systray so that i can control it?
can it be done?
SysTray
Is there any way (VB or not) that i can get rid of the systray icon without closing the program down, in particular the program Mirc, I wanna it that way so the program is hidden when on
Thanks
SysTray????
Is there any way (VB or not) that i can get rid of a tray icon, in particular the mirc tray icon when its minimized....?
Thanks
SysTray
Hi, I have the following code which tells when the user has clicked on my minimized-to-systray icon.
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msgCallBackMessage As Long
msgCallBackMessage = X / Screen.TwipsPerPixelX
Select Case msgCallBackMessage
Case WM_MOUSEMOVE: MySysTray.TipText = MySysTray.PopUpMessage
Case WM_LBUTTONDOWN: Me.Show
Case WM_RBUTTONDOWN: MsgBox "BSS Action Centre - Unisys Ltd"
End Select
End Sub
I want it to behave like a normal icon, which you have to double click (like outlooks email envelope). How can I go about doing this?
SysTray Help Please!
I've created a program that shrinks into the systray the only problem is that I can't seem to be able to show a menu of some sort on the right mouse click?
Help!
Systray
i am working on ticker application ..where data scroll in a form ..how can i place this ticker the systray..in the lines of yahoo ticker
SysTray.ocx
Can anyone explain to me how I use this damn thing - it was working fine under VB5, now all the properties seem to have changed....
Own Systray
how can i make my own systray..ie. icons added when programs like icq start, etc. i need this for a shell replacement btw, cos not having systray icons is really annoying
SysTray
How do I change the icon Of my Appl in the systray?
Thanks
SysTray!!!
Does someone know how to put a clock in the SysTray? Yes, I know it´s already a clock there but i want to do one on my own. So can someone solve this little problem fo me?¿
SysTray
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
aarony@redwingsoftware.com
adyoung@win.bright.net
SYSTRAY
Hi I am trying to make my application hide and show a icon in the system tray. I found some code to do this and it seems to work in the example but when I run my code it dosen't work.
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Msg As Long
Msg = X
' The message is passed to the X value
' You must set your form's ScaleMode property to pixels in order to get the correct message
If Msg = WM_LBUTTONDBLCLK Then
' The user has double-clicked your icon
Call mnuShow_Click
' Show the window
ElseIf Msg = WM_RBUTTONDOWN Then
' Right-click
PopupMenu mnuPopup
' Popup the menu
End If
End Sub
It seems that the X variable never changes so the condition never gets meet. Even though this works on the sample program. Thank you for you help in advance.
Systray
there's loads of code around that allows a program to minimize to the systray and have a pop-up menu. but none of it (that ive found at least) lets u change the icon used without first removing it and then adding it again. id also like to be able to use icons with more than 16 colours
anyone help??
Systray
How can I write a program which is not shown in the Task Bar but has an Icon in the SysTray.
Please help
mfG Pueromane
Icon In Systray Bug
I follow the tutorial gave by MS in the linkhttp://support.microsoft.com/default...;en-us;Q162613 , with the following 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
'Declare the constants for the API function. These constants can be
'found in the header file Shellapi.h.
'The following constants are the messages sent to the
'Shell_NotifyIcon function to add, modify, or delete an icon from the
'taskbar status area.
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status
'area.
Private Const WM_MOUSEMOVE = &H200
'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area.
'Left-click constants.
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
'Right-click constants.
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
'Declare the API function call.
Private Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
'Dimension a variable as the user-defined data type.
Dim nid As NOTIFYICONDATA
Private Sub Command1_Click()
'Click this button to add an icon to the taskbar status area.
'Set the individual values of the NOTIFYICONDATA data type.
nid.cbSize = Len(nid)
nid.hWnd = Form1.hWnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Form1.Icon
nid.szTip = "Taskbar Status Area Sample Program" & vbNullChar
'Call the Shell_NotifyIcon function to add the icon to the taskbar
'status area.
Shell_NotifyIcon NIM_ADD, nid
End Sub
Private Sub Command2_Click()
'Click this button to delete the added icon from the taskbar
'status area by calling the Shell_NotifyIcon function.
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_Load()
'Set the captions of the command button when the form loads.
Command1.Caption = "Add an Icon"
Command2.Caption = "Delete Icon"
End Sub
Private Sub Form_Terminate()
'Delete the added icon from the taskbar status area when the
'program ends.
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub Form_MouseMove _
(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
'Event occurs when the mouse pointer is within the rectangular
'boundaries of the icon in the taskbar status area.
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
CommonDialog1.DialogTitle = "Select an Icon"
sFilter = "Icon Files (*.ico)|*.ico"
sFilter = sFilter & "|All Files (*.*)|*.*"
CommonDialog1.Filter = sFilter
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Form1.Icon = LoadPicture(CommonDialog1.FileName)
nid.hIcon = Form1.Icon
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONDOWN
Dim ToolTipString As String
ToolTipString = InputBox("Enter the new ToolTip:", _
"Change ToolTip")
If ToolTipString <> "" Then
nid.szTip = ToolTipString & vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End If
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK
End Select
End Sub
</code>
It works fine, but always you move the mouse in the right, top-right portion of the form (if it is maximized) it sends the WM_LBUTTONDBLCLK message. Somebody knows how to fix it ? It's incredible that MS has published this code with this bug...
Systray ? (yes I Searched)
All the code I have found for minimizing to systemtray uses the minimize button(which i think is this: Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single), well what if i want to use an image? ... Private Sub imgPoop_Click(Button As Integer, Shift As Integer, X As Single, Y As Single) doesnt work...didnt think it would...but you might see what im saying, anyone know?
SysTray.OCX Problems
i have an app that I am trying to minimize to the systray and that all works fine but I need to change the icon to some thing else that the standard thing. only problem is that it wont let me change it at all.
i have tried to set the icon in the properties but it doesn't change it
I have tried this code to change it also
Code:
Private Sub Command2_Click()
Form1.Hide
cSysTray1.InTray = True
cSysTray1.TrayIcon = App.Path & " emp.bmp" 'but I get an error saying invalid use of property here
End Sub
Any ideas on why it wont let me change the icon?
Thanks for any help
GeeK
Application In Systray...
I want to put my application in the systray instead of the taskbar. I know who to remove it from the taskbar but how can I place an icon in the systray?
I want to minimize and maximize the application using the systray icon.
Any help would be appreciated
Pop-up Menu In Systray
Hi
I'm using an ActiveX object (csystray) to place an icon on the systray.
I add a menu and try to pop it up over the icon, when someone clicks there.
I do this :
(form is set in pixels -- tried point and the same outcome -- only I can't get + 50 and -200 to work at all)
Private Sub cSysTray1_MouseDown(Button As Integer, Id As Long)
Dim P As POINTAPI
Dim D As Long
SetForegroundWindow (Form1.hwnd)
GetCursorPos P
PopupMenu Form1.mnu_to_pop_up , , P.x + 50, P.y - 200
End Sub
I do the + 50 and -200 to get a decent pop-up positioning, but I quite envy other programs in systray that pop-up the menu right above where I click the mouse.
Am I doing something wrong here?
Thanks!
Systray And Balloons...
Hi...
My applications uses a notify icon for showing tooltip balloons on tray. But I cant find a way to identify the balloons, soo I could manage to do different actions for diferent balloons/messages.
Right now I use Shell_NotifyIconA API to create the notify icon and show the balloons. NOTIFYICONDATAA structure that is send on that API have a iID var, but I cant get any info about identifying those balloons.
My objective is the possibility to display diferent messages and do diferent actions as the user click's on it.
Does anyone know how to do this?
Systray Interaction
Ok, I'm writing a little app that functions like a notifier. I don't want the notifier to take up space in the screen, so I want to stuff the thing in the systray. So I started looking and came across this:
Code:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" _
(ByVal dwMessage As Long, IpData As NOTIFYICONDATA) As Long
Public Const ICON_MESSAGE = 1
Public Const ICON_ICON = 2
Public Const ICON_TIP = 4
Public Const ADD_ICON = 0
Public Const MODIFY_ICON = 1
Public Const DELETE_ICON = 2
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
Type NOTIFYICONDATA 'Information structure for the system tray
cbSize As Long 'icon.
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Public IconData As NOTIFYICONDATA 'Stores the information about the TNA Icon
Public Sub CreateSysIcon()
''-------------------------------------------------------''
'' Sets variables for Taskbar Notification Area icon and ''
'' displays it. ''
''-------------------------------------------------------''
Dim result As Long
IconData.cbSize = Len(IconData)
IconData.hWnd = frm_Main.hWnd 'The Form You Want To Handle The Clicks
IconData.uId = vbNull
IconData.uFlags = ICON_MESSAGE Or ICON_ICON Or ICON_TIP
IconData.hIcon = frm_Main.Icon 'The Name Of The Picture Control Containing The Icon
IconData.szTip = "Currently 0 new messages, last updated at 000-00-00 00:00:00"
IconData.ucallbackMessage = WM_RBUTTONDOWN
result = Shell_NotifyIcon(DELETE_ICON, IconData)
result = Shell_NotifyIcon(ADD_ICON, IconData)
End Sub
With credits to the original creator anthony_n ofcourse.
I've got the code to work, replaced the picturebox with the icon of a form (made more sense to me) but otherwise did not edit the code.
But now.... I want to form different kinds of actions on the systray object.
rightclick: a small menu (open something, and close the program)
left doubleclick: open main frm with all the settings and stuff
The code above is great if you want to just create an icon in the systray, but I don't understand how to interact with the icon? It doesnt seem to have any events?
Hope someone can help me out here, TIA
Systray Problems
Hello!
I have to do with systray icons. So, I've searched the web, found the solution (at the end of message). Everything goes ok, but at one moment my application don't respond at mousemove event. I tried to find what happened. And I remember that at start mine application has only one form, and once I added one more (from an existin one) and after this I've deleted this.
Do you think you could help me?
This is the solution
Step one: Declare necessary items
This step is really easy - copy and paste. There isn't anything to do here, but is required to be exact (to my knowledge) so as to run.
Code:
Code:
Option Explicit
'User-defined variable to pass to the Shell_NotiyIcon function
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
'Constants for the Shell_NotifyIcon function
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
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
'Declare the API function call
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim nid As NOTIFYICONDATA
Step two: Create add icon procedure
In this step, we're creating the add icon procedure as a separate procedure so that we can:
Specify a tooltip on-the-fly
Call the add icon procedure from where ever we choose
Code:
Code:
Public Sub AddIcon(ByVal ToolTip As String)
On Error GoTo ErrorHandler
'Add icon to system tray
With nid
.cbSize = Len(nid)
.hWnd = Me.hWnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon
.szTip = ToolTip & vbNullChar
End With
Call Shell_NotifyIcon(NIM_ADD, nid)
Exit Sub
ErrorHandler: 'Display error message
Screen.MousePointer = vbDefault
MsgBox Err.Description, vbInformation, App.ProductName & " - " & Me.Caption
End Sub
Step three: Add code to add icon and remove icon from the system tray
Very straight-forward. Because we've created an add icon procedure, it's one line to add the icon (and modify the tooltip) and one line to remove it.
Code:
Code:
Private Sub Form_Load()
Call AddIcon("This would be a tooltip...")
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'Remove icon from system tray
Call Shell_NotifyIcon(NIM_DELETE, nid)
End Sub
Step four: Interact with system tray icon
Code:
Quote:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
On Error GoTo ErrorHandler
'Respond to user interaction
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDBLCLK
'nothing
Case WM_LBUTTONDOWN
'nothing
Case WM_LBUTTONUP
If Me.WindowState = vbMinimized Then
Me.WindowState = vbNormal
Me.Show
Else
Me.WindowState = vbMinimized
Me.Hide
End If
Case WM_RBUTTONDBLCLK
'nothing
Case WM_RBUTTONDOWN
'nothing
Case WM_RBUTTONUP
'nothing
End Select
Exit Sub
ErrorHandler: 'Display error message
Screen.MousePointer = vbDefault
MsgBox Err.Description, vbInformation, App.ProductName & " - " & Me.Caption
End Sub
Systray Icon
I have an icon in the system tray, and the menu for it is mnuTray. I have two items in this menu: mnuShowHide, and mnuExitTray. When I double click the icon, I want it to Call mnuShowHide_Click. How can I do this?
Systray Icon
I have used several different examples of code from this forum that places an icon into the system tray..but have noticed that when I exit the application the icon remains in the system tray until I mouse over it.
Is this normal or is there another line of code that will remove this.
Here is the code I am using.
!!STRANGE I guess I should say sometimes because it is working now but wasn't the last dozen times I tried it.
Code:
'this code goes into the form
'--------------------------------------------
Private Sub Form_Load()
Me.Hide 'form must be fully visible(NOT!)
Me.Refresh
With nid 'with system tray
.cbSize = Len(nid)
.hwnd = Me.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon 'use form's icon in tray
.szTip = "System Tray Example" & vbNullChar 'tooltip text
End With
Shell_NotifyIcon NIM_ADD, nid 'add to tray
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Result, Action As Long
'there are two display modes and we need to find out
'which one the application is using
If Me.ScaleMode = vbPixels Then
Action = X 'this is used if the form is visible
Else
Action = X / Screen.TwipsPerPixelX 'this is used if the form is not visible
End If
Select Case Action
'the next four lines will show the form if not commented out
' Case WM_LBUTTONDBLCLK 'Left Button Double Click
' Me.WindowState = vbNormal 'put into taskbar
' Result = SetForegroundWindow(Me.hwnd)
' Me.Show 'show form
Case WM_RBUTTONUP 'Right Button Up
Result = SetForegroundWindow(Me.hwnd)
PopupMenu mnuFile 'popup menu, cool eh?
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer) 'on form unload
Shell_NotifyIcon NIM_DELETE, nid 'remove from tray
End Sub
Private Sub mnuExit_Click() 'this menu is added on the form Ctrl+e
Unload Me: End
End Sub
Private Sub mnuSomething_Click() 'same as above, add options if needed
MsgBox "this does nothing"
End Sub
'---------------------------------
'this code goes into the module, it doesn't matter what you call it
'-----------------------------------
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
Public Const NIM_ADD = &H0 'Add to Tray
Public Const NIM_MODIFY = &H1 'Modify Details
Public Const NIM_DELETE = &H2 'Remove From Tray
Public Const NIF_MESSAGE = &H1 'Message
Public Const NIF_ICON = &H2 'Icon
Public Const NIF_TIP = &H4 'TooTipText
Public Const WM_MOUSEMOVE = &H200 'On Mousemove
Public Const WM_LBUTTONDOWN = &H201 'Left Button Down
Public Const WM_LBUTTONUP = &H202 'Left Button Up
Public Const WM_LBUTTONDBLCLK = &H203 'Left Double Click
Public Const WM_RBUTTONDOWN = &H204 'Right Button Down
Public Const WM_RBUTTONUP = &H205 'Right Button Up
Public Const WM_RBUTTONDBLCLK = &H206 'Right Double Click
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public nid As NOTIFYICONDATA
SysTray Balloon
When i minimize my program to the systray, i want to display a balloon such as the one used by win xp. Is there a control or API to do this or is it not possible? -Thanks
Systray Handles
I'm making a shell program I almost finished it i want to know if you can add the system tray into my program. I've seen other shells do it before I'm asking if anyone know how to retrieve the systray handle.
-Hao Li-
SysTray Icon
How can I modify an Icon stored in SysTray when I use the Shell_NotifyIcon to store it...???
How To Use A SysTray Icon???
How can I have my icon display in the system tray? Also, is there a way to make it have a right-click menu? TIA!
SysTray Question
I have an application that I've installed into the system tray. I've created a pop-up menu that is activated when you right click on the icon.
How do I create the "Hot Keys" for the pop-up menu ? Using the ampersand (&) character in the menu name doesn't trigger the click event for that menu item as normally happens on forms.
Thanks
Systray Question
I've been experimenting with using the systray as of late. I've been using The Hand's Forum Checker as a guide of sorts on how to do it. I only have working model edition at home, so I used his proj and then just got rid of all the forms and added new forms just to figure out how to do things. (can't add the user control for Systray in working model edition, but you can modify programs that have them already.. don't ask =p)
I've gotten just about everything working, but one thing i've noticed is that there is nothing preventing multiple instances of the program from running. So, if you were to compile an .exe file and run it, then close the form (leaving the prog in systray), and run the exe again, you would have two of programs running and 2 icons in the systray.
My question is: What would be the best way of going about preventing this? I'm afraid this is a bit beyond my ability at the moment. I have very little actual experience with VB (2 semesters of it), and am just messing around with it on my own currently.
|